-
Notifications
You must be signed in to change notification settings - Fork 111
/
MyChrome.au3
3602 lines (3257 loc) · 129 KB
/
MyChrome.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
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Icon_1.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=Google Chrome Portable
#AutoIt3Wrapper_Res_Fileversion=3.8.1.0
#AutoIt3Wrapper_Res_LegalCopyright=甲壳虫<[email protected]>
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_AU3Check_Parameters=-q
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <WinAPIReg.au3>
#include <WinAPIMisc.au3>
#include <WinAPISys.au3>
#include <Misc.au3>
#include <InetConstants.au3>
#include "WinHttp.au3" ; http://www.autoitscript.com/forum/topic/84133-winhttp-functions/
#include "AppUserModelId.au3"
#include "AppMute.au3"
Global $WinVersion = _WinAPI_GetVersion()
Global Const $AppVersion = "3.8.1" ; MyChrome version
Global $AppName = StringRegExpReplace(@ScriptName, "\.[^.]*$", "")
Global $inifile = @ScriptDir & "\" & $AppName & ".ini"
Global $Language = IniRead($inifile, "Settings", "Language", "Auto")
Global $LangFile = LangCheck()
Global $ProxyType, $ProxySever, $ProxyPort
Global $UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 Chrome/56.0.2924.87 Safari/537.36"
#include "SimpleMultiThreading.au3"
#include "IAccessible.au3"
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode", 1)
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
Global $FirstRun = 0, $ChromePath, $ChromeDir, $ChromeExe, $UserDataDir, $Params
Global $CacheDir, $CacheSize, $PortableParam
Global $ChromeSource = "Google", $get_latest_chrome_ver = "get_latest_chrome_ver"
Global $LastCheckUpdate, $UpdateInterval, $Channel, $IsUpdating = 0, $x86 = 0
Global $AppUpdate, $AppUpdateLastCheck
Global $RunInBackground, $ExApp, $ExAppAutoExit, $ExApp2, $AppPID_Browser, $ExAppPID
Global $TaskBarDir = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
Global $TaskBarLastChange
Global $aExApp, $aExApp2, $aExAppPID[2]
Global $dicKeys, $Bosskey, $BosskeyM, $Hide2Tray
Global $KeepLastTab
Global $MouseClick2CloseTab ; LDClick|RClick + MClick
Global $Mouse2SwitchTab
Global $CancelAppUpdate
Global $hSettings, $SettingsOK
Global $hSettingsOK, $hSettingsApply, $hStausbar
Global $hChromePath, $hGetChromePath, $hChromeSource, $hCheckUpdate
Global $hChannel, $hx86, $hUpdateInterval, $hLatestChromeVer, $hCurrentVer, $hUserDataDir, $hCopyData, $hUrlList
Global $hAppUpdate, $hCacheDir, $hSelectCacheDir, $hCacheSize
Global $hParams, $hDownloadThreads, $hProxyType, $hProxySever, $hProxyPort
Global $hRunInBackground, $hLanguage, $hExApp, $hExAppAutoExit, $hExApp2
Global $hBosskey, $hBosskeyM, $hBosskeyM1, $hBosskeyM2, $hWndProc, $hHide2Tray
Global $hKeepLastTab, $hDoubleClick2CloseTab, $hRightClick2CloseTab, $hMouse2SwitchTab
Global $ChromeFileVersion, $ChromeLastChange, $LatestChromeVer, $LatestChromeUrls, $SelectedUrl
Global $DefaultChromeDir, $DefaultChromeVer, $DefaultUserDataDir
Global $TrayTipProgress = 0
Global $iThreadPid, $DownloadThreads
; Mouse events
Const $AU3_LCLICK = 0x0400 + 0x1A02
Const $AU3_LDCLICK = 0x0400 + 0x1A04
Const $AU3_LDROP = 0x0400 + 0x1A06
Const $AU3_RCLICK = 0x0400 + 0x1B02
Const $AU3_RDCLICK = 0x0400 + 0x1B04
Const $AU3_RDROP = 0x0400 + 0x1B06
Const $AU3_MCLICK = 0x0400 + 0x1C02
Const $AU3_MDCLICK = 0x0400 + 0x1C04
Const $AU3_MDROP = 0x0400 + 0x1C06
Const $AU3_XCLICK = 0x0400 + 0x1D02
Const $AU3_XDCLICK = 0x0400 + 0x1D04
Const $AU3_XDROP = 0x0400 + 0x1D06
Const $AU3_WHEELUP = 0x0400 + 0x1F02
Const $AU3_WHEELDOWN = 0x0400 + 0x1F04
;Const $WH_MOUSE = 7
Global $ChromeIsHidden
Global $hHookDll, $hHookLib, $hMouseHook
Global $hEvent_Reg, $ClientKey, $Progid
Global $aREG[6][3] = [[$HKEY_CURRENT_USER, 'Software\Clients\StartMenuInternet'], _
[$HKEY_LOCAL_MACHINE, 'Software\Clients\StartMenuInternet'], _
[$HKEY_CLASSES_ROOT, 'ftp'], _
[$HKEY_CLASSES_ROOT, 'http'], _
[$HKEY_CLASSES_ROOT, 'https'], _
[$HKEY_CLASSES_ROOT, '']] ; ChromeHTML.XXX
; Global Const $KEY_WOW64_32KEY = 0x0200 ; Access a 32-bit key from either a 32-bit or 64-bit application
; Global Const $KEY_WOW64_64KEY = 0x0100 ; Access a 64-bit key from either a 32-bit or 64-bit application
If Not @AutoItX64 Then ; 32-bit Autoit
$HKLM_Software_32 = "HKLM\SOFTWARE"
$HKLM_Software_64 = "HKLM64\SOFTWARE"
Else ; 64-bit Autoit
$HKLM_Software_32 = "HKLM\SOFTWARE\Wow6432Node"
$HKLM_Software_64 = "HKLM64\SOFTWARE"
EndIf
Global $aFileAsso[6] = [".htm", ".html", ".shtml", ".webp", ".xht", ".xhtml"]
Global $aUrlAsso[13] = ["ftp", "http", "https", "irc", "mailto", "mms", "news", "nntp", "sms", "smsto", "tel", "urn", "webcal"]
FileChangeDir(@ScriptDir)
Global $EnvID = RegRead('HKLM64\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
$EnvID &= RegRead("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate")
$EnvID &= DriveGetSerial(@HomeDrive & "\")
$EnvID = StringTrimLeft(_WinAPI_HashString($EnvID, 0, 16), 2)
If Not FileExists($inifile) Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
IniWrite($inifile, "Settings", "Language", "Auto")
IniWrite($inifile, "Settings", "ChromePath", ".\Chrome\chrome.exe")
IniWrite($inifile, "Settings", "UserDataDir", ".\User Data")
IniWrite($inifile, "Settings", "CacheDir", "")
IniWrite($inifile, "Settings", "CacheSize", 0)
IniWrite($inifile, "Settings", "Channel", "Stable")
IniWrite($inifile, "Settings", "x86", 0)
IniWrite($inifile, "Settings", "ChromeSource", "Google")
IniWrite($inifile, "Settings", "LastCheckUpdate", "2016/05/01 00:00:00")
IniWrite($inifile, "Settings", "UpdateInterval", 24)
IniWrite($inifile, "Settings", "ProxyType", "SYSTEM")
IniWrite($inifile, "Settings", "UpdateProxy", "")
IniWrite($inifile, "Settings", "UpdatePort", "")
IniWrite($inifile, "Settings", "DownloadThreads", 3)
IniWrite($inifile, "Settings", "Params", "")
IniWrite($inifile, "Settings", "RunInBackground", 1)
IniWrite($inifile, "Settings", "AppUpdate", 1)
IniWrite($inifile, "Settings", "AppUpdateLastCheck", "2016/05/01 00:00:00")
IniWrite($inifile, "Settings", "CheckDefaultBrowser", 1)
IniWrite($inifile, "Settings", "ExApp", "")
IniWrite($inifile, "Settings", "ExAppAutoExit", 1)
IniWrite($inifile, "Settings", "ExApp2", "")
IniWrite($inifile, "Settings", "Bosskey", "!x") ; Alt+x
IniWrite($inifile, "Settings", "BosskeyM", $AU3_RDCLICK)
IniWrite($inifile, "Settings", "Hide2Tray", 1)
IniWrite($inifile, "Settings", "MouseClick2CloseTab", $AU3_LDCLICK)
IniWrite($inifile, "Settings", "Mouse2SwitchTab", $AU3_WHEELDOWN & "|" & $AU3_WHEELUP)
IniWrite($inifile, "Settings", "KeepLastTab", 0)
EndIf
; read ini info
$ChromePath = IniRead($inifile, "Settings", "ChromePath", ".\Chrome\chrome.exe")
$UserDataDir = IniRead($inifile, "Settings", "UserDataDir", ".\User Data")
$CacheDir = IniRead($inifile, "Settings", "CacheDir", "")
$CacheSize = IniRead($inifile, "Settings", "CacheSize", 0) * 1
$Channel = IniRead($inifile, "Settings", "Channel", "Stable")
$x86 = IniRead($inifile, "Settings", "x86", 0) * 1
$ChromeSource = IniRead($inifile, "Settings", "ChromeSource", "Google")
If $ChromeSource = "sina.com.cn" Then
$get_latest_chrome_ver = "get_latest_chrome_ver_sina"
Else
$get_latest_chrome_ver = "get_latest_chrome_ver"
EndIf
$LastCheckUpdate = IniRead($inifile, "Settings", "LastCheckUpdate", "2016/05/01 00:00:00")
$UpdateInterval = IniRead($inifile, "Settings", "UpdateInterval", 24) * 1
$ProxyType = IniRead($inifile, "Settings", "ProxyType", "SYSTEM")
$ProxySever = IniRead($inifile, "Settings", "UpdateProxy", "")
$ProxyPort = IniRead($inifile, "Settings", "UpdatePort", "")
$DownloadThreads = IniRead($inifile, "Settings", "DownloadThreads", 3) * 1
$Params = IniRead($inifile, "Settings", "Params", "")
$RunInBackground = IniRead($inifile, "Settings", "RunInBackground", 1) * 1
$AppUpdate = IniRead($inifile, "Settings", "AppUpdate", 1) * 1
$AppUpdateLastCheck = IniRead($inifile, "Settings", "AppUpdateLastCheck", "2016/05/01 00:00:00")
$CheckDefaultBrowser = IniRead($inifile, "Settings", "CheckDefaultBrowser", 1) * 1
$ExApp = IniRead($inifile, "Settings", "ExApp", "")
$ExAppAutoExit = IniRead($inifile, "Settings", "ExAppAutoExit", 1) * 1
$ExApp2 = IniRead($inifile, "Settings", "ExApp2", "")
$Bosskey = IniRead($inifile, "Settings", "Bosskey", "!x")
$BosskeyM = IniRead($inifile, "Settings", "BosskeyM", $AU3_RDCLICK)
$Hide2Tray = IniRead($inifile, "Settings", "Hide2Tray", 1) * 1
$MouseClick2CloseTab = IniRead($inifile, "Settings", "MouseClick2CloseTab", $AU3_LDCLICK)
$Mouse2SwitchTab = IniRead($inifile, "Settings", "Mouse2SwitchTab", $AU3_WHEELDOWN & "|" & $AU3_WHEELUP)
$KeepLastTab = IniRead($inifile, "Settings", "KeepLastTab", 0) * 1
#Region ========= Deal with old MyChrome =========
If $AppVersion <> IniRead($inifile, "Settings", "AppVersion", "") Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
EndIf
#EndRegion ========= Deal with old MyChrome =========
Opt("ExpandEnvStrings", 1)
EnvSet("APP", @ScriptDir)
; Show settings GUI if The first cmdline parameter is "-set",
; or first run, Chrome.exe or userdata not exists
If ($cmdline[0] = 1 And $cmdline[1] = "-set") Or $FirstRun Or Not FileExists($ChromePath) Or Not FileExists($UserDataDir) Then
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
Settings()
EndIf
$ChromePath = FullPath($ChromePath)
SplitPath($ChromePath, $ChromeDir, $ChromeExe)
$UserDataDir = FullPath($UserDataDir)
If IsAdmin() And $cmdline[0] = 1 And $cmdline[1] = "-SetDefaultGlobal" Then
CheckDefaultBrowser($ChromePath)
Exit
EndIf
CheckEnv()
;~ write file "First Run" to prevent chrome from generating shortcut on desktop
If Not FileExists($ChromeDir & "\First Run") Then FileWrite($ChromeDir & "\First Run", "")
; quote external cmdline.
For $i = 1 To $cmdline[0]
If StringInStr($cmdline[$i], " ") Then
$Params &= ' "' & $cmdline[$i] & '"'
Else
$Params &= ' ' & $cmdline[$i]
EndIf
Next
; $PortableParam = '--no-default-browser-check'
$PortableParam = '--user-data-dir="' & $UserDataDir & '"'
If $CacheDir <> "" Then
$CacheDir = FullPath($CacheDir)
$PortableParam &= ' --disk-cache-dir="' & $CacheDir & '"'
EndIf
If $CacheSize <> 0 Then
$PortableParam &= ' --disk-cache-size=' & $CacheSize
EndIf
Local $ChromeIsRunning = AppIsRunning($ChromePath)
If Not $ChromeIsRunning And FileExists($ChromeDir & "\~updated") Then
ApplyUpdate()
EndIf
; start chrome
$AppPID_Browser = Run('"' & $ChromePath & '" ' & $PortableParam & ' ' & $Params, $ChromeDir)
FileChangeDir(@ScriptDir)
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
; check if another instance of mychrome is running
If @Compiled Then
$list = ProcessList(StringRegExpReplace(@AutoItExe, ".*\\", ""))
For $i = 1 To $list[0][0]
If $list[$i][1] <> @AutoItPID And GetProcPath($list[$i][1]) = @AutoItExe Then
Exit ;exit if another instance of mychrome is running
EndIf
Next
EndIf
; Start external apps
If $ExApp <> "" Then
$aExApp = StringSplit($ExApp, "||", 1)
ReDim $aExAppPID[$aExApp[0] + 1]
$aExAppPID[0] = $aExApp[0]
For $i = 1 To $aExApp[0]
$match = StringRegExp($aExApp[$i], '^"(.*?)" *(.*)', 1)
If @error Then
$file = $aExApp[$i]
$args = ""
Else
$file = $match[0]
$args = $match[1]
EndIf
$file = FullPath($file)
$aExAppPID[$i] = ProcessExists(StringRegExpReplace($file, '.*\\', ''))
If Not $aExAppPID[$i] And FileExists($file) Then
$aExAppPID[$i] = ShellExecute($file, $args, StringRegExpReplace($file, '\\[^\\]+$', ''))
EndIf
Next
EndIf
If $CheckDefaultBrowser Then
CheckDefaultBrowser($ChromePath)
EndIf
WinWait("[REGEXPCLASS:(?i)Chrome; REGEXPTITLE:\S+]", "", 10) ; wait fo Chrome / Chromium window
For $i = 1 To 5
$hWnd_Browser = GethWndbyPID($AppPID_Browser, "Chrome", "\S+")
If $hWnd_Browser Then ExitLoop
Sleep(2000)
Next
Global $AppUserModelId
If FileExists($TaskBarDir) Then ; win 7+
$AppUserModelId = _WindowAppId($hWnd_Browser)
CheckPinnedPrograms($ChromePath)
EndIf
Global $FirstUpdateCheck = 1
If Not $RunInBackground Then
UpdateCheck()
Exit
EndIf
; ========================= app ended if not run in background ================================
If $CheckDefaultBrowser Then ; register REG for notification
$hEvent_Reg = _WinAPI_CreateEvent()
For $i = 0 To UBound($aREG) - 1
If $aREG[$i][1] Then
$aREG[$i][2] = _WinAPI_RegOpenKey($aREG[$i][0], $aREG[$i][1], $KEY_NOTIFY)
If $aREG[$i][2] Then
_WinAPI_RegNotifyChangeKeyValue($aREG[$i][2], $REG_NOTIFY_CHANGE_LAST_SET, 1, 1, $hEvent_Reg)
EndIf
EndIf
Next
OnAutoItExitRegister("CloseRegHandle")
EndIf
If $KeepLastTab Or $MouseClick2CloseTab Or $Mouse2SwitchTab Then
AccessibleIni()
EndIf
If $Bosskey Then
HotKeySet($Bosskey, "Bosskey")
EndIf
If $BosskeyM Or $KeepLastTab Or $MouseClick2CloseTab Or $Mouse2SwitchTab Then
HookMouse()
EndIf
If $Bosskey Or $BosskeyM Then
OnAutoItExitRegister("ResumeWindows")
EndIf
AdlibRegister("UpdateCheck", 10000)
ReduceMemory()
; wait for chrome exit
$AppIsRunning = 1
While 1
Sleep(500)
If $hWnd_Browser Then
$AppIsRunning = WinExists($hWnd_Browser)
Else ; ProcessExists() is resource consuming than WinExists()
$AppIsRunning = ProcessExists($AppPID_Browser)
EndIf
If Not $AppIsRunning Then
; check other chrome instance
$AppPID_Browser = AppIsRunning($ChromePath)
If Not $AppPID_Browser Then
ExitLoop
EndIf
$AppIsRunning = 1
$hWnd_Browser = GethWndbyPID($AppPID_Browser, "Chrome", "\S+")
EndIf
If $TaskBarLastChange Then
CheckPinnedPrograms($ChromePath)
EndIf
If $hEvent_Reg And Not _WinAPI_WaitForSingleObject($hEvent_Reg, 0) Then
; MsgBox(0, "", "Reg changed!")
Sleep(50)
CheckDefaultBrowser($ChromePath)
For $i = 0 To UBound($aREG) - 1
If $aREG[$i][2] Then
_WinAPI_RegNotifyChangeKeyValue($aREG[$i][2], $REG_NOTIFY_CHANGE_LAST_SET, 1, 1, $hEvent_Reg)
EndIf
Next
EndIf
WEnd
If $ExAppAutoExit And $ExApp <> "" Then
$cmd = ''
For $i = 1 To $aExAppPID[0]
If Not $aExAppPID[$i] Then ContinueLoop
$cmd &= ' /PID ' & $aExAppPID[$i]
Next
If $cmd Then
$cmd = 'taskkill' & $cmd & ' /T /F'
Run(@ComSpec & ' /c ' & $cmd, '', @SW_HIDE)
EndIf
EndIf
; Start external apps
If $ExApp2 <> "" Then
$aExApp2 = StringSplit($ExApp2, "||", 1)
For $i = 1 To $aExApp2[0]
$match = StringRegExp($aExApp2[$i], '^"(.*?)" *(.*)', 1)
If @error Then
$file = $aExApp2[$i]
$args = ""
Else
$file = $match[0]
$args = $match[1]
EndIf
$file = FullPath($file)
If Not ProcessExists(StringRegExpReplace($file, '.*\\', '')) Then
If FileExists($file) Then
ShellExecute($file, $args, StringRegExpReplace($file, '\\[^\\]+$', ''))
EndIf
EndIf
Next
EndIf
If 0 Then
; put functions here to prevent these functions from being stripped
get_latest_chrome_ver("Stable")
get_latest_chrome_ver_sina("Stable")
download_chrome("", "")
EndIf
Exit
; ==================== auto-exec codes ends ========================
; https://www.autoitscript.com/forum/topic/103362-monitoring-mouse-events/
Func Mouse_Event($hGUI, $MsgID, $wParam, $lParam)
$x = BitAND($lParam, 0x0000FFFF) ;LoWord
$y = BitShift($lParam, 16) ;HiWord
$blocked = BitAND($MsgID, 0x00000001)
$event = BitAND($MsgID, 0xFFFFFFFE)
If WinGetProcess($wParam) <> $AppPID_Browser Then
If $blocked Then
PassMouseEvent($event)
EndIf
Return
EndIf
$tPoint = DllStructCreate($tagPOINT)
$tPoint.X = $x
$tPoint.Y = $y
$hWnd = _WinAPI_WindowFromPoint($tPoint)
$class = _WinAPI_GetClassName($hWnd)
If $event = $AU3_RCLICK And _IsPressed("10") Then ; Shift + right click
If $blocked Then
PassMouseEvent($event)
EndIf
Return
EndIf
;$time = TimerInit()
Local $blockEvent = 0
If $class = "Chrome_RenderWidgetHostHWND" Then
If $event = $BosskeyM Then
If $blocked Then
DllCall($hHookDll, "int", "IgnoreEvents", "int", 1)
Switch $event
Case $AU3_RDCLICK, $AU3_RDROP
MouseUp("left") ; disable context menu
Case $AU3_MDROP
MouseUp("middle")
Case $AU3_MDCLICK
MouseDown("middle")
EndSwitch
Sleep(50)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 0)
$blockEvent = 1
EndIf
Bosskey()
EndIf
ElseIf $class = "Chrome_WidgetWin_1" Then
If ($KeepLastTab And ($event = $AU3_MCLICK Or $event = $AU3_LCLICK)) Or _
StringInStr($MouseClick2CloseTab, $event) Or _
StringInStr($Mouse2SwitchTab, $event) Then
$blockEvent = TabProcess($hWnd, $event, $x, $y)
EndIf
EndIf
;ConsoleWrite(Round(TimerDiff($time), 1) & " Event: " & $event & " on " & $class & ", block: " & $blocked & " --> " & $blockEvent & @LF)
If $blocked And Not $blockEvent Then
PassMouseEvent($event)
EndIf
EndFunc ;==>Mouse_Event
Func PassMouseEvent($event)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 1)
Switch $event
Case $AU3_LCLICK, $AU3_LDROP
MouseUp("left")
Case $AU3_LDCLICK
MouseDown("left")
Case $AU3_RCLICK, $AU3_RDCLICK, $AU3_RDROP
MouseUp("right")
Case $AU3_MCLICK, $AU3_MDROP
MouseUp("middle")
Case $AU3_MDCLICK
MouseDown("middle")
Case $AU3_XCLICK, $AU3_XDROP
_WinAPI_Mouse_Event($MOUSEEVENTF_XUP)
Case $AU3_XDCLICK
_WinAPI_Mouse_Event($MOUSEEVENTF_XDOWN)
EndSwitch
Sleep(50)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 0)
EndFunc ;==>PassMouseEvent
Func HookMouse()
Local $hookdll, $iPID = 0
If @AutoItX64 Then
$hookdll = $ChromeDir & "\hook64.dll"
FileInstall("hook64.dll", $hookdll, 1)
Else
$hookdll = $ChromeDir & "\hook.dll"
FileInstall("hook.dll", $hookdll, 1)
EndIf
$hHookDll = DllOpen($hookdll)
If $hHookDll = -1 Then Return
OnAutoItExitRegister("UnhookMouse")
$hHookLib = _WinAPI_LoadLibrary($hookdll)
$mouseHOOKproc = _WinAPI_GetProcAddress($hHookLib, "MouseProc")
If Not $mouseHOOKproc Then Return
$iThread = _WinAPI_GetWindowThreadProcessId($hWnd_Browser, $iPID)
;If Not $iThread Then Return
$hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE, $mouseHOOKproc, $hHookLib, $iThread)
Local $events = "|" & $BosskeyM & "|" & $MouseClick2CloseTab
If $KeepLastTab Then
$events &= "|" & $AU3_MCLICK
EndIf
$events &= "|" & $Mouse2SwitchTab
;ConsoleWrite('Mouse events registered: ' & $events & @CRLF)
Local $blockevents = $AU3_RCLICK & "|" & $AU3_RDCLICK & "|" & $AU3_RDROP & "|" & $AU3_MCLICK
DllCall($hHookDll, "int", "SetValuesMouse", _
"hwnd", $__hwnd_vars, "hwnd", $hMouseHook)
DllCall($hHookDll, "int", "MouseEvents", "str", $events)
DllCall($hHookDll, "int", "BlockEvents", "str", $blockevents)
;GUIRegisterMsg($AU3_LCLICK, "Mouse_Event")
;GUIRegisterMsg($AU3_LCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_LDCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_LDCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_LDROP, "Mouse_Event")
GUIRegisterMsg($AU3_LDROP + 1, "Mouse_Event")
GUIRegisterMsg($AU3_RCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_RCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_RDCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_RDCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_RDROP, "Mouse_Event")
GUIRegisterMsg($AU3_RDROP + 1, "Mouse_Event")
GUIRegisterMsg($AU3_MCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_MCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_MDCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_MDCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_MDROP, "Mouse_Event")
GUIRegisterMsg($AU3_MDROP + 1, "Mouse_Event")
GUIRegisterMsg($AU3_XCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_XCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_XDCLICK, "Mouse_Event")
GUIRegisterMsg($AU3_XDCLICK + 1, "Mouse_Event")
GUIRegisterMsg($AU3_XDROP, "Mouse_Event")
GUIRegisterMsg($AU3_XDROP + 1, "Mouse_Event")
GUIRegisterMsg($AU3_WHEELUP, "Mouse_Event")
GUIRegisterMsg($AU3_WHEELUP + 1, "Mouse_Event")
GUIRegisterMsg($AU3_WHEELDOWN, "Mouse_Event")
GUIRegisterMsg($AU3_WHEELDOWN + 1, "Mouse_Event")
EndFunc ;==>HookMouse
Func UnhookMouse()
_WinAPI_UnhookWindowsHookEx($hMouseHook)
_WinAPI_FreeLibrary($hHookLib)
DllClose($hHookDll)
EndFunc ;==>UnhookMouse
Func TabProcess($hWnd, $action = $AU3_RCLICK, $mouseX = 0, $mouseY = 0)
; Possible $action values: $AU3_LCLICK, $AU3_LDCLICK, $AU3_RCLICK, $AU3_MCLICK, $AU3_WHEELUP, $AU3_WHEELDOWN
;ConsoleWrite($action & ", Mouse positon: $mouseX " & $mouseX & ", $mouseY " & $mouseY & @CRLF)
Local $pAcc, $oAcc, $tVarChild
AccessibleObjectFromPoint($mouseX, $mouseY, $pAcc, $tVarChild)
If @error Then Return
$oAcc = ObjCreateInterface($pAcc, $sIID_IAccessible, $dtagIAccessible)
If Not IsObj($oAcc) Then Return
Local $iRole, $aTab[2]
$oAcc.get_accRole(0, $iRole)
If $iRole = $ROLE_SYSTEM_PAGETAB Then
Dim $aTab[2] = [$pAcc, $oAcc]
ElseIf $iRole <> $ROLE_SYSTEM_STATICTEXT And $iRole <> $ROLE_SYSTEM_PUSHBUTTON Then
Return
EndIf
If Not IsObj($aTab[1]) Then
$aTab = AccessibleParent($oAcc, $ROLE_SYSTEM_PAGETAB, 1)
If Not IsArray($aTab) Then
;ConsoleWrite("Mouse is not on a page tab. Ignore and return..." & @CRLF)
Return
EndIf
EndIf
;ConsoleWrite("Mouse is on a page tab. " & @CRLF)
If $action = $AU3_WHEELUP Then
Send("^{PGUP}")
Return
ElseIf $action = $AU3_WHEELDOWN Then
Send("^{PGDN}")
Return
EndIf
Local $iTab = 0
$aTabList = AccessibleParent($aTab[1], $ROLE_SYSTEM_PAGETABLIST, 1)
If Not IsArray($aTabList) Or $aTabList[1].get_accChildCount($iTab) Or Not $iTab Then
Return
EndIf
$iTab -= 1
If $iTab > 1 Then ; more than one tab
;ConsoleWrite("There are " & $iTab & " tabs within Chrome window. " & @CRLF)
If $action = $AU3_LDCLICK Or $action = $AU3_RCLICK Then
DllCall($hHookDll, "int", "IgnoreEvents", "int", 1)
$pos = MouseGetPos()
MouseMove($mouseX, $mouseY, 0)
MouseClick("middle", $mouseX, $mouseY, 1, 0)
MouseMove($pos[0], $pos[1], 0)
Sleep(10)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 0)
Return 1 ; block evnet
;$aTabClose = AccessibleChildren($aTab[0], $aTab[1], $ROLE_SYSTEM_PUSHBUTTON, 0, 1)
;If IsArray($aTabClose) Then
; $aTabClose[1].accDoDefaultAction(0)
; Return 1 ; block event
;EndIf
EndIf
Return
EndIf
;ConsoleWrite("There is ONLY one tab within Chrome window. " & @CRLF)
If $KeepLastTab Then
Send("^t")
Sleep(50)
EndIf
If $action = $AU3_LDCLICK Or $action = $AU3_RCLICK Then
;ConsoleWrite("Close the old tab and return..." & @CRLF)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 1)
$pos = MouseGetPos()
MouseMove($mouseX, $mouseY, 0)
MouseClick("middle", $mouseX, $mouseY, 1, 0)
MouseMove($pos[0], $pos[1], 0)
Sleep(10)
DllCall($hHookDll, "int", "IgnoreEvents", "int", 0)
;$aTabClose = AccessibleChildren($aTab[0], $aTab[1], $ROLE_SYSTEM_PUSHBUTTON, 0, 1)
;If Not IsArray($aTabClose) Then Return
;$aTabClose[1].accDoDefaultAction(0)
EndIf
If $action = $AU3_RCLICK Then
Return 1 ; block event
EndIf
EndFunc ;==>TabProcess
Func Bosskey()
Local $aList, $pid
If $ChromeIsHidden Then
ResumeWindows()
Else
$aList = WinList("[REGEXPCLASS:(?i)Chrome; REGEXPTITLE:\S+]")
;_ArrayDisplay($aList)
If $aList[0][0] < 1 Then Return
For $i = 1 To $aList[0][0]
If BitAND(WinGetState($aList[$i][1]), 2) Then ; ignore hidden windows
$pid = WinGetProcess($aList[$i][1])
If $pid = $AppPID_Browser Then
WinSetState($aList[$i][1], "", @SW_HIDE)
$ChromeIsHidden = 1
EndIf
EndIf
Next
If VersionCompare($WinVersion, "6.1") >= 0 Then ; Windows 7 or later
Audio_SetAppMute($AppPID_Browser, 1)
EndIf
If $Hide2Tray Then
TraySetIcon($ChromePath)
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "ResumeWindows")
TraySetState(1)
TraySetToolTip(StringFormat(lang("GUI", "UnhideChrome", 'Chrome已隐藏\n点击取消隐藏'), 0))
EndIf
EndIf
EndFunc ;==>Bosskey
Func ResumeWindows()
If $Hide2Tray Then
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "")
TraySetToolTip()
TraySetIcon()
TraySetState(2)
EndIf
Local $aList, $pid
$aList = WinList("[REGEXPCLASS:(?i)Chrome; REGEXPTITLE:\S+]")
If $aList[0][0] < 1 Then Return
For $i = 1 To $aList[0][0]
If Not BitAND(WinGetState($aList[$i][1]), 2) Then ; hidden windows
$pid = WinGetProcess($aList[$i][1])
If $pid = $AppPID_Browser Or GetProcPath($pid) = $ChromePath Then
WinSetState($aList[$i][1], "", @SW_SHOW)
EndIf
EndIf
Next
$ChromeIsHidden = 0
If VersionCompare($WinVersion, "6.1") >= 0 Then
Audio_SetAppMute($AppPID_Browser, 0)
EndIf
EndFunc ;==>ResumeWindows
Func LangCheck()
If $Language = "Auto" And FileExists(@ScriptDir & "\lang\lang.ini") Then
Return @ScriptDir & "\lang\lang.ini"
EndIf
Local $lngfile
If $Language = "zh-CN" Then
Return "" ; Chinese simplified (default)
ElseIf $Language = "zh-TW" Then
$lngfile = @ScriptDir & "\lang\zh-TW.ini"
ElseIf $Language = "en-US" Then
$lngfile = @ScriptDir & "\lang\en-US.ini"
EndIf
If Not $lngfile Then
If @OSLang = "0004" Or @OSLang = "0804" Then
Return "" ; Chinese simplified (default)
ElseIf StringRight(@OSLang, 2) = "04" Then
$lngfile = @ScriptDir & "\lang\zh-TW.ini"
EndIf
EndIf
If Not FileExists(@ScriptDir & "\lang") Then
DirCreate(@ScriptDir & "\lang\")
EndIf
If Not $lngfile Then
$lngfile = @ScriptDir & "\lang\en-US.ini"
EndIf
If $lngfile = @ScriptDir & "\lang\zh-TW.ini" Then
If Not FileExists($lngfile) Or IniRead($lngfile, "Lang", "Version", "") <> $AppVersion Then
FileInstall("zh-TW.ini", $lngfile, 1)
EndIf
Else ; $lngfile = @ScriptDir & "\en-US.ini"
If Not FileExists($lngfile) Or IniRead($lngfile, "Lang", "Version", "") <> $AppVersion Then
FileInstall("en-US.ini", $lngfile, 1)
EndIf
EndIf
Return $lngfile
EndFunc ;==>LangCheck
Func lang($Section, $Key, $DefaltStr)
If Not $LangFile Then
Return $DefaltStr
Else
Return IniRead($LangFile, $Section, $Key, $DefaltStr)
EndIf
EndFunc ;==>lang
;#include <WinAPI.au3>
Func GetIEProxy(ByRef $Sever, ByRef $Port)
$Sever = ""
$Port = ""
Local $aIEproxy = _WinHttpGetIEProxyConfigForCurrentUser()
If Not @error Then
$sProxy = $aIEproxy[2]
If Not $sProxy And $aIEproxy[1] Then
; https://www.autoitscript.com/forum/topic/84133-winhttp-functions/?page=27
$pacAddress = $aIEproxy[1]
Local $WINHTTP_AUTOPROXY_OPTIONS = DllStructCreate("dword dwFlags;" & _
"dword dwAutoDetectFlags;" & _
"ptr lpszAutoConfigUrl;" & _
"ptr lpvReserved;" & _
"dword dwReserved;" & _
"dword fAutoLogonIfChallenged;")
Local $WINHTTP_PROXY_INFO = DllStructCreate("dword AccessType;ptr Proxy;ptr ProxyBypass")
DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "dwFlags", $WINHTTP_AUTOPROXY_CONFIG_URL)
DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "dwAutoDetectFlags", _
BitOR($WINHTTP_AUTO_DETECT_TYPE_DHCP, $WINHTTP_AUTO_DETECT_TYPE_DNS_A))
Local $tPacAddress = DllStructCreate("wchar[" & StringLen($pacAddress) + 1 & "]")
DllStructSetData($tPacAddress, 1, $pacAddress)
DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "lpszAutoConfigUrl", DllStructGetPtr($tPacAddress))
Local $hOpen = _WinHttpOpen()
$url = "https://www.google.com"
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpGetProxyForUrl", _
"handle", $hOpen, _
"wstr", $url, _
"struct*", DllStructGetPtr($WINHTTP_AUTOPROXY_OPTIONS), _
"struct*", DllStructGetPtr($WINHTTP_PROXY_INFO))
;ConsoleWrite("_WinAPI_GetLastError: " & _WinAPI_GetLastError() & @CRLF)
_WinHttpCloseHandle($hOpen)
Local $pProxy = DllStructGetData($WINHTTP_PROXY_INFO, "Proxy")
$sProxy = DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW($pProxy) & "]", $pProxy), 1)
EndIf
Local $match
If StringInStr($sProxy, "https=") Then
$match = StringRegExp($sProxy, '(?i)https=(\S+?:\d+)', 1)
If Not @error Then $sProxy = $match[0]
ElseIf StringInStr($sProxy, "http=") Then
$match = StringRegExp($sProxy, '(?i)http=(\S+?:\d+)', 1)
If Not @error Then $sProxy = $match[0]
EndIf
$pos = StringInStr($sProxy, ":")
If $pos Then
$Sever = StringLeft($sProxy, $pos - 1)
$Port = StringMid($sProxy, $pos + 1)
EndIf
EndIf
EndFunc ;==>GetIEProxy
Func GethWndbyPID($pid, $class = ".*", $title = ".*")
$list = WinList("[REGEXPCLASS:(?i)" & $class & "; REGEXPTITLE:(?i)" & $title & "]")
For $i = 1 To $list[0][0]
If Not BitAND(WinGetState($list[$i][1]), 2) Then ContinueLoop ; ignore hidden windows
If $pid = WinGetProcess($list[$i][1]) Then
;ConsoleWrite("--> " & $list[$i][1] & "-" & $list[$i][0] & @CRLF)
Return $list[$i][1]
EndIf
Next
EndFunc ;==>GethWndbyPID
Func GetChromeLastChange($path)
; chrome "LastChange" changed from digits as 312162 to commit hashes
; chrome release : 800fe26985bd6fd8626dd80f710fae8ac527bd6b-refs/branch-heads/2171@{#470}
; chromium : 32cbfaa6478f66b93b6d383a58f606960e02441e-refs/heads/master@{#312162}
Local $match = StringRegExp(FileGetVersion($path, "LastChange"), '(\d{6,})\D*$', 1)
If Not @error Then Return $match[0]
Return ""
EndFunc ;==>GetChromeLastChange
Func CheckEnv()
Local $oldstr, $var, $EnvString, $variations_seed, $variations_seed_signature
$EnvString = FileRead($UserDataDir & "\EnvId")
If $EnvString = $EnvID Then Return
FileDelete($UserDataDir & "\EnvId")
If FileExists($UserDataDir & "\Local State") Then
$EnvString = FileWrite($UserDataDir & "\EnvId", $EnvID)
FileInstall(".\Local State.MyChrome", $UserDataDir & "\Local State.MyChrome", 1)
$var = FileRead($UserDataDir & "\Local State.MyChrome")
FileDelete($UserDataDir & "\Local State.MyChrome")
Local $match = StringRegExp($var, '(?i)("variations.*_seed": *"\S+?")', 1)
If Not @error Then $variations_seed = $match[0]
$match = StringRegExp($var, '(?i)("variations_seed_signature": *"\S+?")', 1)
If Not @error Then $variations_seed_signature = $match[0]
$oldstr = FileRead($UserDataDir & "\Local State")
$var = StringRegExpReplace($oldstr, '(?i)"variations.*_seed": *"\S+?"', $variations_seed)
If Not @error Then
$var = StringRegExpReplace($var, '(?i)"variations_seed_signature": *"\S+?"', $variations_seed_signature)
If $var <> $oldstr Then
Local $file = FileOpen($UserDataDir & "\Local State", 2 + 256)
FileWrite($file, $var)
FileClose($file)
EndIf
EndIf
EndIf
EndFunc ;==>CheckEnv
Func CloseRegHandle()
If $hEvent_Reg Then
_WinAPI_CloseHandle($hEvent_Reg)
For $i = 0 To UBound($aREG) - 1
_WinAPI_RegCloseKey($aREG[$i][2])
Next
EndIf
EndFunc ;==>CloseRegHandle
Func UpdateCheck()
Local $updated, $var
; Check mychrome update
If $AppUpdate <> 0 And _DateDiff("h", $AppUpdateLastCheck, _NowCalc()) >= 24 Then
CheckAppUpdate()
EndIf
; check chrome update
If $UpdateInterval >= 0 Then
If $UpdateInterval = 0 Then
If $FirstUpdateCheck Then
$updated = UpdateChrome($ChromePath, $Channel)
EndIf
Else
Local $var = _DateDiff("h", $LastCheckUpdate, _NowCalc())
If $var >= $UpdateInterval Then
$updated = UpdateChrome($ChromePath, $Channel)
EndIf
EndIf
If $updated And Not AppIsRunning($ChromePath) Then ; restart app/chrome
If @Compiled Then
Run('"' & @AutoItExe & '" --restore-last-session')
Else
Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" --restore-last-session')
EndIf
Exit
EndIf
EndIf
If $RunInBackground Then
If $FirstUpdateCheck Then
AdlibRegister("UpdateCheck", 300000)
EndIf
ReduceMemory()
EndIf
$FirstUpdateCheck = 0
EndFunc ;==>UpdateCheck
; for win7+
Func CheckPinnedPrograms($browser_path)
If Not FileExists($TaskBarDir) Then
Return
EndIf
Local $ftime = FileGetTime($TaskBarDir, 0, 1)
If $ftime = $TaskBarLastChange Then
Return
EndIf
$TaskBarLastChange = $ftime
Local $search = FileFindFirstFile($TaskBarDir & "\*.lnk")
If $search = -1 Then Return
Local $file, $ShellObj, $objShortcut, $shortcut_appid
$ShellObj = ObjCreate("WScript.Shell")
If Not @error Then
While 1
$file = $TaskBarDir & "\" & FileFindNextFile($search)
If @error Then ExitLoop
$objShortcut = $ShellObj.CreateShortCut($file)
$path = $objShortcut.TargetPath
If $path == $browser_path Or $path == @ScriptFullPath Then
If $path == $browser_path Then
$objShortcut.TargetPath = @ScriptFullPath
$objShortcut.Save
$TaskBarLastChange = FileGetTime($TaskBarDir, 0, 1)
EndIf
$shortcut_appid = _ShortcutAppId($file)
If Not $AppUserModelId Then
If Not $hWnd_Browser Then
Sleep(3000)
$hWnd_Browser = GethWndbyPID($AppPID_Browser, "Chrome", "\S+")
EndIf
$AppUserModelId = _WindowAppId($hWnd_Browser)
If Not $AppUserModelId Then
If $shortcut_appid Then
$AppUserModelId = $shortcut_appid
Else ; if no window appid found,set an id for the window
$AppUserModelId = "MyChrome." & StringTrimLeft(_WinAPI_HashString(@ScriptFullPath, 0, 16), 2)
EndIf
_WindowAppId($hWnd_Browser, $AppUserModelId)
EndIf
EndIf
If $shortcut_appid <> $AppUserModelId Then
_ShortcutAppId($file, $AppUserModelId)
$TaskBarLastChange = FileGetTime($TaskBarDir, 0, 1)
EndIf
ExitLoop
EndIf
WEnd
$objShortcut = ""
$ShellObj = ""
EndIf
FileClose($search)
EndFunc ;==>CheckPinnedPrograms