forked from rcmaehl/MSEdgeRedirect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSEdgeRedirect.au3
1205 lines (996 loc) · 44.2 KB
/
MSEdgeRedirect.au3
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
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Assets\MSEdgeRedirect.ico
#AutoIt3Wrapper_Outfile=MSEdgeRedirect_x86.exe
#AutoIt3Wrapper_Outfile_x64=MSEdgeRedirect.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=https://www.msedgeredirect.com
#AutoIt3Wrapper_Res_Description=A Tool to Redirect News, Search, Widgets, Weather and More to Your Default Browser
#AutoIt3Wrapper_Res_Fileversion=0.5.0.0
#AutoIt3Wrapper_Res_ProductName=MSEdgeRedirect
#AutoIt3Wrapper_Res_ProductVersion=0.5.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Robert Maehl, using LGPL 3 License
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Compatibility=Win8,Win81,Win10
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -v1 -v2 -v3
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#AutoIt3Wrapper_Res_Icon_Add=Assets\MSEdgeRedirect.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <Misc.au3>
#include <Array.au3>
#include <String.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
#include <WinAPIShPath.au3>
#include <EditConstants.au3>
#include <TrayConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "Includes\_Theming.au3"
#include "Includes\ResourcesEx.au3"
Opt("TrayMenuMode", 3)
Opt("TrayAutoPause", 0)
Opt("GUICloseOnESC", 0)
Global $aEdges[5] = [4, _
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", _
"C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe", _
"C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe", _
@LocalAppDataDir & "\Microsoft\Edge SXS\Application\msedge.exe"]
Global $sVersion = "0.5.0.0"
SetupAppdata()
Global $hLogs[3] = _
[FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\AppFailures.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\AppGeneral.log", $FO_APPEND), _
FileOpen(@LocalAppDataDir & "\MSEdgeRedirect\logs\URIFailures.log", $FO_APPEND)]
RunArchCheck()
RunHTTPCheck()
ProcessCMDLine()
Func ActiveMode(ByRef $aCMDLine)
Local $sCMDLine = ""
Select
Case $aCMDLine[0] = 1 ; No Parameters
ReDim $aCMDLine[3]
$aCMDLine[2] = ""
ContinueCase
Case $aCMDLine[0] = 2 And $aCMDLine[2] = "--inprivate" ; In Private Browsing, No Parameters
$aCMDLine[1] = StringReplace($aCMDLine[1], "msedge.exe", "msedge_no_ifeo.exe")
ShellExecute($aCMDLine[1], $aCMDLine[2])
Case Else
For $iLoop = 2 To $aCMDLine[0]
$sCMDLine &= $aCMDLine[$iLoop] & " "
Next
_DecodeAndRun($sCMDLine)
EndSelect
EndFunc
Func ProcessCMDLine()
Local $aMUI[2] = [Null, @MUILang]
Local $aPIDs
Local $bHide = False
Local $iParams = $CmdLine[0]
Local $bSilent = False
Local $aInstall[3]
Local $bPortable = False
If DriveGetType(@ScriptDir) = "Removable" Then $bPortable = True
If $iParams > 0 Then
;_ArrayDisplay($CmdLine)
If _ArraySearch($aEdges, $CmdLine[1]) > 0 Then ; Image File Execution Options Mode
ActiveMode($CmdLine)
If _GetSettingValue("NoUpdates") And Random(1, 10, 1) = 1 Then
Switch _GetLatestRelease($sVersion)
Case -1
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Test Build?"), _Translate($aMUI[1], "You're running a newer build than publicly Available!"), 10)
Case 1
If MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TOPMOST, _Translate($aMUI[1], "Update Available"), _Translate($aMUI[1], "An Update is Available, would you like to download it?"), 10) = $IDYES Then ShellExecute("https://fcofix.org/MSEdgeRedirect/releases")
EndSwitch
EndIf
Exit
EndIf
Do
Switch $CmdLine[1]
Case "/?", "/help"
MsgBox(0, "Help and Flags", _
"Checks PC for Windows 11 Release Compatibility" & @CRLF & _
@CRLF & _
"MSEdgeRedirect [/hide]" & @CRLF & _
@CRLF & _
@TAB & "/hide " & @TAB & "Hides the tray icon" & @CRLF & _
@TAB & "/update" & @TAB & "Downloads the latest RELEASE (default) or DEV build" & @CRLF & _
@CRLF & _
@CRLF)
Exit 0
Case "/change"
RunSetup(True, $bSilent)
Exit
Case "/h", "/hide"
$bHide = True
_ArrayDelete($CmdLine, 1)
Case "/p", "/portable"
$bPortable = True
_ArrayDelete($CmdLine, 1)
Case "/repair"
RunRepair()
Exit
Case "/si", "/silentinstall"
$bSilent = True
_ArrayDelete($CmdLine, 1)
Case "/u", "/update"
Select
Case UBound($CmdLine) = 2
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, 1)
Case UBound($CmdLine) > 2 And $CmdLine[2] = "dev"
InetGet("https://nightly.link/rcmaehl/MSEdgeRedirect/workflows/mser/main/mser.zip", @ScriptDir & "\WhyNotWin11_dev.zip")
_ArrayDelete($CmdLine, "1-2")
Case UBound($CmdLine) > 2 And $CmdLine[2] = "release"
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, "1-2")
Case StringLeft($CmdLine[2], 1) = "/"
InetGet("https://fcofix.org/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe", @ScriptDir & "\MSEdgeRedirect_Latest.exe")
_ArrayDelete($CmdLine, 1)
Case Else
MsgBox(0, "Invalid", 'Invalid release type - "' & $CmdLine[2] & "." & @CRLF)
Exit 87 ; ERROR_INVALID_PARAMETER
EndSelect
Case "/uninstall"
RunRemoval()
Exit
Case Else
If @Compiled Then ; support for running non-compiled script - mLipok
MsgBox(0, "Invalid", 'Invalid parameter - "' & $CmdLine[1] & "." & @CRLF)
Exit 87 ; ERROR_INVALID_PARAMETER
EndIf
EndSwitch
Until UBound($CmdLine) <= 1
Else
;;;
EndIf
If Not $bPortable Then
$aInstall = _IsInstalled()
Select
Case Not $aInstall[0] ; Not Installed
RunSetup(False, $bSilent)
Case _VersionCompare($sVersion, $aInstall[2]) ; Installed, Out of Date
RunSetup($aInstall[1], $bSilent)
Case StringInStr($aInstall[1], "HKCU") ; Installed, Up to Date, Service Mode
If Not @ScriptDir = @LocalAppDataDir & "\MSEdgeRedirect" Then
ShellExecute(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", "", @LocalAppDataDir & "\MSEdgeRedirect\")
Else
$aPIDs = ProcessList(@ScriptName)
For $iLoop = 1 To $aPIDs[0][0] Step 1
If $aPIDs[$iLoop][1] <> @AutoItPID Then
$bHide = False
ProcessClose($aPIDs[$iLoop][1])
EndIf
Next
EndIf
Case Else
Exit
EndSelect
EndIf
ReactiveMode($bHide)
EndFunc
Func ReactiveMode($bHide = False)
Local $aMUI[2] = [Null, @MUILang]
Local $hTimer = TimerInit()
Local $aAdjust
Local $hMsg
; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)
TrayCreateItem($sVersion)
TrayItemSetState(-1, $TRAY_DISABLE)
TrayCreateItem("")
Local $hStartup = TrayCreateItem("Start With Windows")
Local $hUpdate = TrayCreateItem("Check for Updates")
TrayCreateItem("")
Local $hDonate = TrayCreateItem("Donate")
TrayCreateItem("")
Local $hHide = TrayCreateItem("Hide Icon")
Local $hExit = TrayCreateItem("Exit")
If $bHide Then TraySetState($TRAY_ICONSTATE_HIDE)
If FileExists(@StartupDir & "\MSEdgeRedirect.lnk") Then TrayItemSetState($hStartup, $TRAY_CHECKED)
Local $aProcessList
Local $sCommandline
While True
$hMsg = TrayGetMsg()
If TimerDiff($hTimer) >= 100 Then
$aProcessList = ProcessList("msedge.exe")
For $iLoop = 1 To $aProcessList[0][0] - 1
$sCommandline = _WinAPI_GetProcessCommandLine($aProcessList[$iLoop][1])
If (StringInStr($sCommandline, "microsoft-edge:") And Not StringInStr($sCommandline, "--inprivate")) Or StringInStr($sCommandline, "--app-id") Then
ProcessClose($aProcessList[$iLoop][1])
If _ArraySearch($aEdges, _WinAPI_GetProcessFileName($aProcessList[$iLoop][1]), 1, $aEdges[0]) > 0 Then
_DecodeAndRun($sCommandline)
EndIf
EndIf
Next
$hTimer = TimerInit()
EndIf
Select
Case $hMsg = $hHide
TraySetState($TRAY_ICONSTATE_HIDE)
Case $hMsg = $hExit
ExitLoop
Case $hMsg = $hDonate
ShellExecute("https://paypal.me/rhsky")
Case $hMsg = $hUpdate
Switch _GetLatestRelease($sVersion)
Case -1
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Test Build?"), _Translate($aMUI[1], "You're running a newer build than publicly Available!"), 10)
Case 0
Switch @error
Case 0
MsgBox($MB_OK + $MB_ICONINFORMATION + $MB_TOPMOST, _Translate($aMUI[1], "Up to Date"), _Translate($aMUI[1], "You're running the latest build!"), 10)
Case 1
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Unable to Check for Updates"), _Translate($aMUI[1], "Unable to load release data."), 10)
Case 2
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Unable to Check for Updates"), _Translate($aMUI[1], "Invalid Data Received!"), 10)
Case 3
Switch @extended
Case 0
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Unable to Check for Updates"), _Translate($aMUI[1], "Invalid Release Tags Received!"), 10)
Case 1
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Unable to Check for Updates"), _Translate($aMUI[1], "Invalid Release Types Received!"), 10)
EndSwitch
EndSwitch
Case 1
If MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TOPMOST, _Translate($aMUI[1], "Update Available"), _Translate($aMUI[1], "An Update is Available, would you like to download it?"), 10) = $IDYES Then ShellExecute("https://fcofix.org/MSEdgeRedirect/releases")
EndSwitch
Case $hMsg = $hStartup
If Not FileExists(@StartupDir & "\MSEdgeRedirect.lnk") Then
FileCreateShortcut(@AutoItExe, @StartupDir & "\MSEdgeRedirect.lnk", @ScriptDir)
TrayItemSetState($hStartup, $TRAY_CHECKED)
ElseIf FileExists(@StartupDir & "\MSEdgeRedirect.lnk") Then
FileDelete(@StartupDir & "\MSEdgeRedirect.lnk")
TrayItemSetState($hStartup, $TRAY_UNCHECKED)
EndIf
Case Else
EndSelect
WEnd
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit
EndFunc
Func RunArchCheck()
If @Compiled And @OSArch = "X64" And _WinAPI_IsWow64Process() Then
MsgBox($MB_ICONERROR+$MB_OK, "Wrong Version", "The 64-bit Version of MSEdgeRedirect must be used with 64-bit Windows!")
FileWrite($hLogs[0], _NowCalc() & " - " & "32 Bit Version on 64 Bit System. EXITING!" & @CRLF)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit 216 ; ERROR_EXE_MACHINE_TYPE_MISMATCH
EndIf
EndFunc
Func RunHTTPCheck()
Local $sHive = ""
If _WinAPI_IsWow64Process() Then
$sHive = "HKCU64"
Else
$sHive = "HKCU"
EndIf
If StringInStr(RegRead($sHive & "\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice", "ProgId"), "MSEdge") Or _
StringInStr(RegRead($sHive & "\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice", "ProgId"), "MSEdge") Then
MsgBox($MB_ICONERROR+$MB_OK, "Edge Set As Default", "You must set a different Default Browser to use MSEdgeRedirect!")
FileWrite($hLogs[0], _NowCalc() & " - " & "Found MS Edge set as default browser, EXITING!" & @CRLF)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit 4315 ; ERROR_MEDIA_INCOMPATIBLE
EndIf
EndFunc
Func RunInstall(ByRef $aConfig, ByRef $aSettings)
Local $sArgs = ""
Local Enum $bManaged, $vMode
Local Enum $bNoApps, $bNoBing, $bNoPDFs, $bNoTray, $bNoUpdates, $sPDFApp, $sSearch, $sSearchPath, $sStartMenu, $bStartup
SetOptionsRegistry("NoApps", $aSettings[$bNoApps], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("NoBing", $aSettings[$bNoBing], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("NoPDFs", $aSettings[$bNoPDFs], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("NoTray", $aSettings[$bNoTray], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("NoUpdates", $aSettings[$bNoUpdates], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("PDFApp", $aSettings[$sPDFApp], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("Search", $aSettings[$sSearch], $aConfig[$vMode], $aConfig[$bManaged])
SetOptionsRegistry("SearchPath", $aSettings[$sSearchPath], $aConfig[$vMode], $aConfig[$bManaged])
If $aConfig[$vMode] Then
FileCopy(@ScriptFullPath, "C:\Program Files\MSEdgeRedirect\MSEdgeRedirect.exe", $FC_CREATEPATH+$FC_OVERWRITE)
Else
If $aSettings[$bNoTray] Then $sArgs = "/hide"
FileCopy(@ScriptFullPath, @LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", $FC_CREATEPATH+$FC_OVERWRITE)
If $aSettings[$bStartup] Then FileCreateShortcut(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", @StartupDir & "\MSEdgeRedirect.lnk")
Switch $aSettings[$sStartMenu]
Case "Full"
DirCreate(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\MSEdgeRedirect")
FileCreateShortcut(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\MSEdgeRedirect\Settings.lnk", @LocalAppDataDir & "\MSEdgeRedirect\", "/change")
ContinueCase
Case "App Only"
DirCreate(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\MSEdgeRedirect")
FileCreateShortcut(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\MSEdgeRedirect\MSEdgeRedirect.lnk", @LocalAppDataDir & "\MSEdgeRedirect\", $sArgs)
Case Else
;;;
EndSwitch
EndIf
EndFunc
Func RunRemoval($bUpdate = False)
Local $aPIDs
Local $sHive = ""
Local $sLocation = ""
$aPIDs = ProcessList("msedgeredirect.exe")
For $iLoop = 1 To $aPIDs[0][0] Step 1
If $aPIDs[$iLoop][1] <> @AutoItPID Then ProcessClose($aPIDs[$iLoop][1])
Next
If IsAdmin() Then
$sLocation = "C:\Program Files\MSEdgeRedirect\"
If _WinAPI_IsWow64Process() Then
$sHive = "HKLM64"
Else
$sHive = "HKLM"
EndIf
Else
$sLocation = @LocalAppDataDir & "\MSEdgeRedirect\"
If _WinAPI_IsWow64Process() Then
$sHive = "HKCU64"
Else
$sHive = "HKCU"
EndIf
EndIf
; App Paths
RegDelete($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSEdgeRedirect.exe")
; App Settings
RegDelete($sHive & "\SOFTWARE\Robert Maehl Software\MSEdgeRedirect")
; URI Handler for Pre Win11 22494 Installs
RegDelete($sHive & "\Software\Classes\MSEdgeRedirect.microsoft-edge")
; Generic Program Info
RegDelete($sHive & "\Software\Classes\MSEdgeRedirect")
RegDelete($sHive & "\Software\Classes\Applications\MSEdgeRedirect.exe")
; IFEO
RegDelete($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe")
; Uninstall Info
RegDelete($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect")
FileDelete(@StartupDir & "\MSEdgeRedirect.lnk")
DirRemove(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\MSEdgeRedirect", $DIR_REMOVE)
If IsAdmin() Then
For $iLoop = 1 To $aEdges[0] Step 1
If FileExists(StringReplace($aEdges[$iLoop], "msedge.exe", "msedge_no_ifeo.exe")) Then
FileDelete(StringReplace($aEdges[$iLoop], "msedge.exe", "msedge_no_ifeo.exe"))
EndIf
Next
EndIf
If $bUpdate Then
FileDelete($sLocation & "*")
Else
Run(@ComSpec & " /c " & 'ping google.com && del /Q "' & $sLocation & '*"', "", @SW_HIDE)
Exit
EndIf
EndFunc
Func RunRepair()
If IsAdmin() Then
For $iLoop = 1 To $aEdges[0] Step 1
If FileExists(StringReplace($aEdges[$iLoop], "msedge.exe", "msedge_no_ifeo.exe")) Then
FileCopy($aEdges[$iLoop], StringReplace($aEdges[$iLoop], "msedge.exe", "msedge_no_ifeo.exe"), $FC_OVERWRITE)
EndIf
Next
Exit
Else
Exit 5 ; ERROR_ACCESS_DENIED
EndIf
EndFunc
Func RunSetup($bUpdate = False, $bSilent = False)
#forceref $bSilent
Local $aMUI[2] = [Null, @MUILang]
Local $hMsg
Local $sArgs = ""
Local $sEdges
Local $sEngine
Local $aHandler
Local $sHandler
Local $bIsAdmin = IsAdmin()
Local $hChannels[4]
Local $aChannels[4] = [True, True, False, False]
Local $aConfig[2] = [False, "Service"] ; Default Setup.ini Values
Local Enum $bManaged, $vMode
Local $aSettings[10] = [False, False, False, False, False, "", "", "", "Full", True]
Local Enum $bNoApps, $bNoBing, $bNoPDFs, $bNoTray, $bNoUpdates, $sPDFApp, $sSearch, $sSearchPath, $sStartMenu, $bStartup
If $bSilent Then
If Not FileExists(@ScriptDir & "\Setup.ini") Then Exit 2 ; ERROR_FILE_NOT_FOUND
$aConfig[$bManaged] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Config", "Managed", False))
$aConfig[$vMode] = IniRead(@ScriptDir & "\Setup.ini", "Config", "Mode", "Service")
If $aConfig[$vMode] = "active" Then
$aConfig[$vMode] = True
Else
$aConfig[$vMode] = False
EndIf
If ($aConfig[$bManaged] Or $aConfig[$vMode]) And Not IsAdmin() Then Exit 5 ; ERROR_ACCESS_DENIED
$sEdges = IniRead(@ScriptDir & "\Setup.ini", "Settings", "Edges", "")
If StringInStr($sEdges, "Stable") Then $aChannels[0] = True
If StringInStr($sEdges, "Beta") Then $aChannels[1] = True
If StringInStr($sEdges, "Dev") Then $aChannels[2] = True
If StringInStr($sEdges, "Canary") Then $aChannels[3] = True
For $iLoop = 0 To 3 Step 1
If $aChannels[$iLoop] = True Then ExitLoop
If $iLoop = 3 Then Exit 160 ; ERROR_BAD_ARGUMENTS
Next
$aSettings[$bNoApps] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "NoApps", $aSettings[$bNoApps]))
$aSettings[$bNoBing] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "NoBing", $aSettings[$bNoBing]))
$aSettings[$bNoPDFs] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "NoPDFs", $aSettings[$bNoPDFs]))
$aSettings[$bNoTray] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "NoTray", $aSettings[$bNoTray]))
$aSettings[$bNoUpdates] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "NoUpdates", $aSettings[$bNoUpdates]))
$aSettings[$sPDFApp] = IniRead(@ScriptDir & "\Setup.ini", "Settings", "PDFApp", $aSettings[$sPDFApp])
$aSettings[$sSearch] = IniRead(@ScriptDir & "\Setup.ini", "Settings", "Search", $aSettings[$sSearch])
$aSettings[$sSearchPath] = IniRead(@ScriptDir & "\Setup.ini", "Settings", "SearchPath", $aSettings[$sSearchPath])
$aSettings[$sStartMenu] = IniRead(@ScriptDir & "\Setup.ini", "Settings", "StartMenu", $aSettings[$sStartMenu])
$aSettings[$bStartup] = _Bool(IniRead(@ScriptDir & "\Setup.ini", "Settings", "Startup", $aSettings[$bStartup]))
For $iLoop = $bNoApps To $bNoUpdates Step 1
If Not IsBool($aSettings[$iLoop]) Then Exit 160 ; ERROR_BAD_ARGUMENTS
Next
If Not IsBool($aSettings[$bStartup]) Then Exit 160 ; ERROR_BAD_ARGUMENTS
RunInstall($aConfig, $aSettings)
SetAppRegistry($aConfig[$vMode])
If $aConfig[$vMode] Then
SetIFEORegistry($aChannels)
Else
If $aSettings[$bNoTray] Then $sArgs = "/hide"
ShellExecute(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", $sArgs, @LocalAppDataDir & "\MSEdgeRedirect\")
EndIf
Exit
Else
If _GetSettingValue("NoUpdates") Then
Switch _GetLatestRelease($sVersion)
Case -1
MsgBox($MB_OK + $MB_ICONWARNING + $MB_TOPMOST, _Translate($aMUI[1], "Test Build?"), _Translate($aMUI[1], "You're running a newer build than publicly Available!"), 10)
Case 1
If MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TOPMOST, _Translate($aMUI[1], "Update Available"), _Translate($aMUI[1], "An Update is Available, would you like to download it?"), 10) = $IDYES Then ShellExecute("https://fcofix.org/MSEdgeRedirect/releases")
EndSwitch
EndIf
If StringInStr($bUpdate, "HKLM") And Not $bIsAdmin And Not @Compiled Then
MsgBox($MB_ICONERROR+$MB_OK, "Admin Required", "Unable to update an Admin Install without Admin Rights!")
FileWrite($hLogs[0], _NowCalc() & " - " & "Non Admin Update Attempt on Admin Install. EXITING!" & @CRLF)
For $iLoop = 0 To UBound($hLogs) - 1
FileClose($hLogs[$iLoop])
Next
Exit 5 ; ERROR_ACCESS_DENIED
EndIf
; Disable Scaling
If @OSVersion = 'WIN_10' Then DllCall(@SystemDir & "\User32.dll", "bool", "SetProcessDpiAwarenessContext", "HWND", "DPI_AWARENESS_CONTEXT" - 1)
Local $hInstallGUI = GUICreate("MSEdge Redirect " & $sVersion & " Setup", 640, 480)
GUICtrlCreateLabel("", 0, 0, 180, 480)
GUICtrlSetBkColor(-1, 0x00A4EF)
GUICtrlCreateIcon("", -1, 26, 26, 128, 128)
If @Compiled Then
_SetBkSelfIcon(-1, "", 0x00A4EF, @ScriptFullPath, 201, 128, 128)
Else
_SetBkIcon(-1, "", 0x00A4EF, @ScriptDir & "\assets\MSEdgeRedirect.ico", -1, 128, 128)
EndIf
#Region License Page
Local $hLicense = GUICreate("", 460, 480, 180, 0, $WS_POPUP, $WS_EX_MDICHILD, $hInstallGUI)
FileInstall("./LICENSE", @LocalAppDataDir & "\MSEdgeRedirect\License.txt")
If $bUpdate Then
GUICtrlCreateLabel("Pleae read the following License. You must accept the terms of the license before continuing with the upgrade.", 20, 20, 420, 40)
Else
GUICtrlCreateLabel("Pleae read the following License. You must accept the terms of the license before continuing with the installation.", 20, 20, 420, 40)
EndIf
GUICtrlCreateEdit("TL;DR: It's FOSS, you can edit it, repackage it, eat it (not recommended), or throw it at your neighbor Steve (depends on the Steve), but changes to it must be LGPL v3 too." & _
@CRLF & @CRLF & _
FileRead(@LocalAppDataDir & "\MSEdgeRedirect\License.txt"), 20, 60, 420, 280, $ES_READONLY + $WS_VSCROLL)
Local $hAgree = GUICtrlCreateRadio("I accept this license", 20, 350, 420, 20)
Local $hDisagree = GUICtrlCreateRadio("I don't accept this license", 20, 370, 420, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
Local $hNext = GUICtrlCreateButton("NEXT", 20, 410, 420, 50)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISwitch($hInstallGUI)
#EndRegion
#Region Install Settings
If $bUpdate Then
GUICtrlCreateLabel("MSEdge Redirect " & $sVersion & " Update", 200, 10, 420, 30)
GUICtrlSetFont(-1, 20, $FW_BOLD, $GUI_FONTNORMAL, "", $CLEARTYPE_QUALITY)
GUICtrlCreateLabel("Click Install to update MS Edge Redirect after customizing your preferred options", 200, 40, 420, 40)
GUICtrlSetFont(-1, 10, $FW_NORMAL, $GUI_FONTNORMAL, "", $CLEARTYPE_QUALITY)
Else
GUICtrlCreateLabel("Install MSEdge Redirect " & $sVersion, 200, 10, 420, 30)
GUICtrlSetFont(-1, 20, $FW_BOLD, $GUI_FONTNORMAL, "", $CLEARTYPE_QUALITY)
GUICtrlCreateLabel("Click Install to install MS Edge Redirect after customizing your preferred options", 200, 40, 420, 40)
GUICtrlSetFont(-1, 10, $FW_NORMAL, $GUI_FONTNORMAL, "", $CLEARTYPE_QUALITY)
EndIf
GUICtrlCreateGroup("Mode", 200, 80, 420, 220)
Local $hService = GUICtrlCreateRadio("Service Mode - Per User" & @CRLF & _
@CRLF & _
"MSEdge Redirect stays running in the background. Detected Edge data is redirected to your default browser.", _
230, 100, 380, 60, $BS_TOP+$BS_MULTILINE)
GUICtrlSetState(-1, $GUI_CHECKED)
Local $hStartup = GUICtrlCreateCheckbox("Start MSEdge Redirect Service With Windows", 250, 160, 320, 20)
Local $hNoIcon = GUICtrlCreateCheckbox("Hide MSEdge Redirect Service Icon from Tray", 250, 180, 320, 20)
GUICtrlCreateIcon("imageres.dll", 78, 210, 210, 16, 16)
Local $hActive = GUICtrlCreateRadio("Active Mode - All Users" & @CRLF & _
@CRLF & _
"MSEdge Redirect only runs when a selected Edge is launched, similary to the old EdgeDeflector app.", _
230, 210, 380, 60, $BS_TOP+$BS_MULTILINE)
$hChannels[0] = GUICtrlCreateCheckbox("Edge Stable", 250, 270, 90, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$hChannels[1] = GUICtrlCreateCheckbox("Edge Beta", 340, 270, 90, 20)
$hChannels[2] = GUICtrlCreateCheckbox("Edge Dev", 430, 270, 90, 20)
$hChannels[3] = GUICtrlCreateCheckbox("Edge Canary", 520, 270, 90, 20)
GUICtrlSetState($hChannels[0], $GUI_DISABLE)
GUICtrlSetState($hChannels[1], $GUI_DISABLE)
GUICtrlSetState($hChannels[2], $GUI_DISABLE)
GUICtrlSetState($hChannels[3], $GUI_DISABLE)
If Not $bIsAdmin Then
GUICtrlSetState($hActive, $GUI_DISABLE)
EndIf
GUICtrlCreateGroup("Options", 200, 300, 420, 100)
Local $hNoApps = GUICtrlCreateCheckbox("De-embed Windows Store 'Apps'", 230, 320, 380, 20)
Local $hNoPDFs = GUICtrlCreateCheckbox("Redirect PDFs to:", 230, 340, 240, 20)
Local $hPDFPath = GUICtrlCreateLabel("",470, 340, 140, 20)
Local $hSearch = GUICtrlCreateCheckbox("Replace Bing Search Results with:", 230, 360, 240, 20)
Local $hEngine = GUICtrlCreateCombo("", 470, 355, 140, 20, $CBS_DROPDOWNLIST+$WS_VSCROLL)
GUICtrlSetData(-1, "Ask|Baidu|Custom|DuckDuckGo|Ecosia|Google|Sogou|Yahoo|Yandex", "Google")
GUICtrlSetState(-1, $GUI_DISABLE)
Local $hInstall = GUICtrlCreateButton("Install", 200, 410, 420, 50)
GUICtrlSetFont(-1, 16, $FW_BOLD, $GUI_FONTNORMAL, "", $CLEARTYPE_QUALITY)
#EndRegion
GUISetState(@SW_SHOW, $hLicense)
GUISetState(@SW_SHOW, $hInstallGUI)
While True
$hMsg = GUIGetMsg()
Select
Case $hMsg = $GUI_EVENT_CLOSE
Exit
Case $hMsg = $hAgree or $hMsg = $hDisagree
If _IsChecked($hAgree) Then
GUICtrlSetState($hNext, $GUI_ENABLE)
Else
GUICtrlSetState($hNext, $GUI_DISABLE)
EndIf
Case $hMsg = $hNext
GUISetState(@SW_HIDE, $hLicense)
Case $hMsg = $hActive or $hMsg = $hService
If _IsChecked($hService) Then
GUICtrlSetState($hInstall, $GUI_ENABLE)
GUICtrlSetState($hStartup, $GUI_ENABLE)
GUICtrlSetState($hNoIcon, $GUI_ENABLE)
GUICtrlSetState($hChannels[0], $GUI_DISABLE)
GUICtrlSetState($hChannels[1], $GUI_DISABLE)
GUICtrlSetState($hChannels[2], $GUI_DISABLE)
GUICtrlSetState($hChannels[3], $GUI_DISABLE)
Else
GUICtrlSetState($hStartup, $GUI_DISABLE)
GUICtrlSetState($hNoIcon, $GUI_DISABLE)
GUICtrlSetState($hChannels[0], $GUI_ENABLE)
GUICtrlSetState($hChannels[1], $GUI_ENABLE)
GUICtrlSetState($hChannels[2], $GUI_ENABLE)
GUICtrlSetState($hChannels[3], $GUI_ENABLE)
ContinueCase
EndIf
Case $hMsg = $hChannels[0] Or $hMsg = $hChannels[1] Or $hMsg = $hChannels[2] Or $hMsg = $hChannels[3]
GUICtrlSetState($hInstall, $GUI_DISABLE)
For $iLoop = 0 To 3 Step 1
If _IsChecked($hChannels[$iLoop]) Then
GUICtrlSetState($hInstall, $GUI_ENABLE)
ExitLoop
EndIf
Next
Case $hMsg = $hSearch
If _IsChecked($hSearch) Then
GUICtrlSetState($hEngine, $GUI_ENABLE)
Else
GUICtrlSetState($hEngine, $GUI_DISABLE)
EndIf
Case $hMsg = $hEngine And GUICtrlRead($hEngine) = "Custom"
$sEngine = InputBox("Enter Search Engine URL", "Enter the URL format of the custom search Engine to use", "https://duckduckgo.com/?q=")
If @error Or Not _WinAPI_UrlIs($sEngine) Then GUICtrlSetData($hEngine, "Google")
Case $hMsg = $hNoPDFs
If _IsChecked($hNoPDFs) Then
$sHandler = FileOpenDialog("Select a PDF Handler", @ProgramFilesDir, "Executables (*.exe)", $FD_FILEMUSTEXIST)
If @error Then
GUICtrlSetState($hNoPDFs, $GUI_UNCHECKED)
Else
$aHandler = StringSplit($sHandler, "\")
GUICtrlSetData($hPDFPath, $aHandler[$aHandler[0]])
EndIf
Else
GUICtrlSetData($hPDFPath, "")
EndIf
Case $hMsg = $hInstall
If $bUpdate Then RunRemoval(True)
$aConfig[$vMode] = _IsChecked($hActive)
$aSettings[$bNoApps] = _IsChecked($hNoApps)
$aSettings[$bNoBing] = _IsChecked($hSearch)
$aSettings[$bNoPDFs] = _IsChecked($hNoPDFs)
$aSettings[$bNoTray] = _IsChecked($hNoIcon)
$aSettings[$sPDFApp] = $sHandler
$aSettings[$sSearch] = GUICtrlRead($hEngine)
$aSettings[$sSearchPath] = $sEngine
$aSettings[$bStartup] = _IsChecked($hStartup)
GUISetState(@SW_HIDE, $hInstallGUI)
RunInstall($aConfig, $aSettings)
SetAppRegistry($aConfig[$vMode])
If $aConfig[$vMode] Then
For $iLoop = 0 To 3 Step 1
$aChannels[$iLoop] = _IsChecked($hChannels[$iLoop])
Next
SetIFEORegistry($aChannels)
Else
If $aSettings[$bNoTray] Then $sArgs = "/hide"
ShellExecute(@LocalAppDataDir & "\MSEdgeRedirect\MSEdgeRedirect.exe", $sArgs, @LocalAppDataDir & "\MSEdgeRedirect\")
EndIf
Exit
Case Else
;;;
EndSelect
WEnd
EndIf
EndFunc
Func SetAppRegistry($bAllUsers)
Local $sHive = ""
Local $sLocation = ""
If $bAllUsers Then
$sLocation = "C:\Program Files\MSEdgeRedirect\"
If _WinAPI_IsWow64Process() Then
$sHive = "HKLM64"
Else
$sHive = "HKLM"
EndIf
Else
$sLocation = @LocalAppDataDir & "\MSEdgeRedirect\"
If _WinAPI_IsWow64Process() Then
$sHive = "HKCU64"
Else
$sHive = "HKCU"
EndIf
EndIf
; App Paths
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSEdgeRedirect.exe", "", "REG_SZ", $sLocation & "MSEdgeRedirect.exe")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSEdgeRedirect.exe", "Path", "REG_SZ", $sLocation)
; URI Handler for Pre Win11 22494 Installs
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSEdgeRedirect.exe", "SupportedProtocols", "REG_SZ", "microsoft-edge")
RegWrite($sHive & "\Software\Classes\MSEdgeRedirect.microsoft-edge", "", "REG_SZ", "URL:microsoft-edge")
RegWrite($sHive & "\Software\Classes\MSEdgeRedirect.microsoft-edge", "URL Protocol", "REG_SZ", "")
RegWrite($sHive & "\Software\Classes\MSEdgeRedirect.microsoft-edge\shell\open\command", "", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe" "%1"')
; Generic Program Info
RegWrite($sHive & "\Software\Classes\MSEdgeRedirect\DefaultIcon", "", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe",0')
RegWrite($sHive & "\Software\Classes\MSEdgeRedirect\shell\open\command", "", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe" "%1"')
RegWrite($sHive & "\Software\Classes\Applications\MSEdgeRedirect.exe", "FriendlyAppName", "REG_SZ", "MSEdgeRedirect")
RegWrite($sHive & "\Software\Classes\Applications\MSEdgeRedirect.exe\DefaultIcon", "", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe",0')
; Uninstall Info
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "DisplayIcon", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe",0')
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "DisplayName", "REG_SZ", "MSEdgeRedirect")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "DisplayVersion", "REG_SZ", $sVersion)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "EstimatedSize", "REG_DWORD", 1536)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "HelpLink", "REG_SZ", "https://msedgeredirect.com/wiki")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "InstallDate", "REG_SZ", StringReplace(_NowCalcDate(), "/", ""))
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "InstallLocation", "REG_SZ", $sLocation)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "Language", "REG_DWORD", 1033)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "ModifyPath", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe" /change')
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "NoModify", "REG_DWORD", 0)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "NoRepair", "REG_DWORD", 1)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "Publisher", "REG_SZ", "Robert Maehl Software")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "Readme", "REG_SZ", "https://msedgeredirect.com/blob/main/README.md")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "UninstallString", "REG_SZ", '"' & $sLocation & 'MSEdgeRedirect.exe" /uninstall')
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "URLInfoAbout", "REG_SZ", "https://msedgeredirect.com")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "URLUpdateInfo", "REG_SZ", "https://msedgeredirect.com/releases")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MSEdgeRedirect", "Version", "REG_SZ", $sVersion)
EndFunc
Func SetIFEORegistry(ByRef $aChannels)
Local $sHive = ""
If _WinAPI_IsWow64Process() Then
$sHive = "HKLM64"
Else
$sHive = "HKLM"
EndIf
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe", "UseFilter", "REG_DWORD", 1)
For $iLoop = 1 To $aEdges[0] Step 1
If $aChannels[$iLoop - 1] Then
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\MSER" & $iLoop)
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\MSER" & $iLoop, "Debugger", "REG_SZ", "C:\Program Files\MSEdgeRedirect\MSEdgeRedirect.exe")
RegWrite($sHive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe\MSER" & $iLoop, "FilterFullPath", "REG_SZ", $aEdges[$iLoop])
FileCopy($aEdges[$iLoop], StringReplace($aEdges[$iLoop], "msedge.exe", "msedge_no_ifeo.exe"), $FC_OVERWRITE)
EndIf
Next
EndFunc
Func SetOptionsRegistry($sName, $vValue, $bAllUsers, $bManaged = False)
Local Static $sHive = ""
Local Static $sPolicy = ""
#forceref $sHive
If $sHive = "" Then
If $bAllUsers Then
If _WinAPI_IsWow64Process() Then
$sHive = "HKLM64"
Else
$sHive = "HKLM"
EndIf
Else
If _WinAPI_IsWow64Process() Then
$sHive = "HKCU64"
Else
$sHive = "HKCU"
EndIf
EndIf
If $bManaged Then $sPolicy = "Policies\"
EndIf
Select
Case IsBool($vValue)
RegWrite($sHive & "\SOFTWARE\" & $sPolicy & "Robert Maehl Software\MSEdgeRedirect\", $sName, "REG_DWORD", $vValue)
Case IsString($vValue)
RegWrite($sHive & "\SOFTWARE\" & $sPolicy & "Robert Maehl Software\MSEdgeRedirect\", $sName, "REG_SZ", $vValue)
Case Else
RegWrite($sHive & "\SOFTWARE\" & $sPolicy & "Robert Maehl Software\MSEdgeRedirect\", $sName, "REG_SZ", $vValue)
EndSelect
EndFunc
Func SetupAppdata()
Select
Case Not FileExists(@LocalAppDataDir & "\MSEdgeRedirect\")
DirCreate(@LocalAppDataDir & "\MSEdgeRedirect\logs\")
ContinueCase
Case Not FileExists(@LocalAppDataDir & "\MSEdgeRedirect\Langs\")
DirCreate(@LocalAppDataDir & "\MSEdgeRedirect\langs\")
Case Else
;;;
EndSelect
EndFunc
Func _Bool($sString)
If $sString = "True" Then
Return True
ElseIf $sString = "False" Then
Return False
Else
Return $sString
EndIf
EndFunc
Func _ChangeSearchEngine($sURL)
If StringInStr($sURL, "bing.com/search?q=") Then
$sURL = StringRegExpReplace($sURL, "(.*)(q=)", "")
Switch _GetSettingValue("Search")
Case "Ask"
Return "https://www.ask.com/web?q=" & $sURL
Case "Baidu"
Return "https://www.baidu.com/s?wd=" & $sURL
Case "Custom"
Return _GetSettingValue("SearchPath") & $sURL
Case "DuckDuckGo"
Return "https://duckduckgo.com/?q=" & $sURL
Case "Ecosia"
Return "https://www.ecosia.org/search?q=" & $sURL
Case "Google"
Return "https://www.google.com/search?q=" & $sURL
Case "Sogou"
Return "https://www.sogou.com/web?query=" & $sURL
Case "Yahoo"
Return "https://search.yahoo.com/search?p=" & $sURL
Case "Yandex"
Return "https://yandex.com/search/?text=" & $sURL
Case Null
Return "https://bing.com/search?q=" & $sURL
Case Else
Return _GetSettingValue("SearchPath") & $sURL
EndSwitch
Else
Return $sURL
EndIf
EndFunc
Func _DecodeAndRun($sCMDLine)
Local $sCaller
Local $aLaunchContext
Select
Case StringInStr($sCMDLine, "--default-search-provider=?")
FileWrite($hLogs[2], _NowCalc() & " - Skipped Settings URL: " & $sCMDLine & @CRLF)
Case StringInStr($sCMDLine, ".pdf") And _GetSettingValue("NoPDFs")
ShellExecute(_GetSettingValue("PDFApp"), $sCMDLine)
Case StringInStr($sCMDLine, "--app-id") And _GetSettingValue("NoApps") ; TikTok and other Apps
$sCMDLine = StringRegExpReplace($sCMDLine, "(.*)(--app-fallback-url=)", "")
$sCMDLine = StringRegExpReplace($sCMDLine, "(?= --)(.*)", "")
ShellExecute($sCMDLine)
Case StringInStr($sCMDLine, "Windows.Widgets")
$sCaller = "Windows.Widgets"
ContinueCase
Case StringRegExp($sCMDLine, "microsoft-edge:[\/]*?\?launchContext1")
$aLaunchContext = StringSplit($sCMDLine, "=")
If $aLaunchContext[0] >= 3 Then
If $sCaller = "" Then $sCaller = $aLaunchContext[2]
FileWrite($hLogs[1], _NowCalc() & " - Redirected Edge Call from: " & $sCaller & @CRLF)
$sCMDLine = _UnicodeURLDecode($aLaunchContext[$aLaunchContext[0]])
If _WinAPI_UrlIs($sCMDLine) Then
If _GetSettingValue("NoBing") Then $sCMDLine = _ChangeSearchEngine($sCMDLine)
ShellExecute($sCMDLine)
Else
FileWrite($hLogs[2], _NowCalc() & " - Invalid Regexed URL: " & $sCMDLine & @CRLF)
EndIf
Else
FileWrite($hLogs[2], _NowCalc() & " - Command Line Missing Needed Parameters: " & $sCMDLine & @CRLF)
EndIf
Case Else
$sCMDLine = StringRegExpReplace($sCMDLine, "(.*) microsoft-edge:[\/]*", "")
If _WinAPI_UrlIs($sCMDLine) Then
If _GetSettingValue("NoBing") Then $sCMDLine = _ChangeSearchEngine($sCMDLine)
ShellExecute($sCMDLine)
Else
FileWrite($hLogs[2], _NowCalc() & " - Invalid URL: " & $sCMDLine & @CRLF)
EndIf
EndSelect
EndFunc
Func _GetSettingValue($sSetting, $bPortable = False)
Local $vReturn = Null
Local $sHive1 = ""
Local $sHive2 = ""
If _WinAPI_IsWow64Process() Then
$sHive1 = "HKLM64"