-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonFunctions.au3
More file actions
1943 lines (1722 loc) · 78.3 KB
/
CommonFunctions.au3
File metadata and controls
1943 lines (1722 loc) · 78.3 KB
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
#include-once
;===============================================================================
; Common functions used in my scripts
; https://github.com/jmclaren7/autoit-scripts/blob/master/CommonFunctions.au3
;===============================================================================
; If these files have already been included using a custom path, you may need to remove them here
#include <Array.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <WinAPIFiles.au3>
#include <WinAPIProc.au3>
#include <WinAPIShPath.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
;===============================================================================
; Function Name: _GUICtrlListView_GetCheckedText
; Description: Gets the text of all checked items in a ListView control
; Call With: _GUICtrlListView_GetCheckedText($hListView)
; Parameter(s): $hListView - Handle of the ListView control
; Return Value(s): On Success - Array of checked item texts (first element is the count)
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 03/8/2026 -- v1.0
;===============================================================================
Func _GUICtrlListView_GetCheckedText($hListView)
Local $aSelected[1] = [0]
For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
If _GUICtrlListView_GetItemChecked($hListView, $i) Then
Local $pkgName = _GUICtrlListView_GetItemText($hListView, $i)
_ArrayAdd($aSelected, $pkgName)
$aSelected[0] += 1
EndIf
Next
Return $aSelected
EndFunc ;==>_GUICtrlListView_GetCheckedText
;===============================================================================
; Function Name: _ControlGetFocus
; Description: Gets the control ID of the focused control in a GUI
; Call With: _ControlGetFocus($hGUI)
; Parameter(s): $hGUI - title/hWnd/class of the GUI to check
; Return Value(s): On Success - Control ID of the focused control
; On Failure - 0, @error set:
; 2 - No control has focus
; 3 - Could not get control handle
; 4 - Could not get control ID
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 03/7/2026 -- v1.0
;===============================================================================
Func _ControlGetFocus($hGUI)
Local $sFocus = ControlGetFocus($hGUI)
If $sFocus = "" Then Return SetError(2, 0, 0)
Local $hFocus = ControlGetHandle($hGUI, "", $sFocus)
If Not IsHWnd($hFocus) Then Return SetError(3, 0, 0)
Local $iCtrlID = _WinAPI_GetDlgCtrlID($hFocus)
If $iCtrlID = 0 Then Return SetError(4, 0, 0)
Return $iCtrlID
EndFunc ;==>_ControlGetFocus
;===============================================================================
; Function Name: _FileGetVersion
; Description: Gets a version segment from a file's version string
; Call With: _FileGetVersion([$File = Default[, $Segment = Default]])
; Parameter(s): $File - [optional] Path to the file (default is the script's path)
; $Segment - [optional] Segment of the version to return (1 = Major, 2 = Minor, etc. - default is last segment)
; Return Value(s): On Success - Version segment as a string
; On Failure - "" (Error code in @error)
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 02/24/2026 -- v1.1
;===============================================================================
Func _FileGetVersion($File = Default, $Segment = Default)
If $File = Default Then $File = @ScriptFullPath
Local $Version = FileGetVersion($File)
If @error Then Return SetError(1, 0, "")
Local $aVersion = StringSplit($Version, ".")
If @error Then Return SetError(2, 0, $Version)
If $Segment = Default Then $Segment = $aVersion[0]
If $Segment < 1 Or $Segment > $aVersion[0] Then Return SetError(3, 0, "")
Return $aVersion[$Segment]
EndFunc ;==>_FileGetVersion
;===============================================================================
; Function Name: _FileSigned
; Description: Verifies a file's digital signature
; Call With: _FileSigned($File)
; Parameter(s): $File - Path to the file to verify
; Return Value(s): On Success - Array containing the status, subject, and thumbprint
; On Failure - 0 (Error code in @error)
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 11/02/2025 -- v1.0
;===============================================================================
Func _FileSigned($File = Default)
If IsObj($File) And IsInt($File.scriptline) Then
Return SetError(1, $File.scriptline, 0)
ElseIf $File = Default Or $File = "" Then
Return SetError(2, 0, 0)
ElseIf Not FileExists($File) Then
Return SetError(3, 0, 0)
EndIf
Local $Run = "powershell.exe -nologo -noprofile -command (Get-AuthenticodeSignature -FilePath '" & $File & "') | Select Status,{$_.SignerCertificate.Subject},{$_.SignerCertificate.Thumbprint} | ConvertTo-XML -As String -NoTypeInformation"
Local $Result = _RunWait($Run)
;_Log($Result)
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_FileSigned")
Local $oXML = ObjCreate("Microsoft.XMLDOM")
If @error Then
Return SetError(4, 0, 0)
EndIf
$oXML.loadXML($Result)
If $oXML.parseError.errorCode <> 0 Then
;"XML Parse Error? Check this: $oXML.parseError.reason
Return SetError(5, 0, 0)
EndIf
;_Log($oXML.xml)
Local $aResult[3]
$aResult[0] = $oXML.selectSingleNode("/Objects/Object/Property[@Name='Status']").text
$aResult[1] = $oXML.selectSingleNode("/Objects/Object/Property[@Name='$_.SignerCertificate.Subject']").text
$aResult[2] = $oXML.selectSingleNode("/Objects/Object/Property[@Name='$_.SignerCertificate.Thumbprint']").text
If $aResult[0] = "Valid" Then
Return SetError(0, 0, $aResult)
Else
Return SetError(6, 0, 0)
EndIf
EndFunc ;==>_FileSigned
;===============================================================================
; Function Name: _HideDrive
; Description: Hide or show a drive from file explorer
; Call With: _HideDrive($DriveLetter, $Hide = True)
; Parameter(s): $DriveLetter - Drive letter to hide or show
; $Hide - [optional] True to hide, False to show
; Return Value(s): None
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 11/02/2025 -- v1.0
;===============================================================================
Func _HideDrive($DriveLetter, $Hide = Default)
If $Hide = Default Then $Hide = True
Local $DriveNumber = Asc(StringUpper($DriveLetter)) - Asc("A")
Local $DriveBit = BitShift(1, -$DriveNumber)
; Get the current value of the NoDrives registry key
Local $CurrentMask = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoDrives")
If @error Then $CurrentMask = 0
; Check if the drive is already in the desired state
Local $IsHidden = BitAND($CurrentMask, $DriveBit) <> 0
If ($Hide And $IsHidden) Or (Not $Hide And Not $IsHidden) Then
_Log("Drive " & $DriveLetter & ": is already " & ($Hide ? "hidden" : "visible") & ".")
Return
EndIf
; Calculate the new value based on if we should hide or show the drive
Local $NewMask
If $Hide Then
$NewMask = BitOR($CurrentMask, $DriveBit)
Else
$NewMask = BitAND($CurrentMask, BitNOT($DriveBit))
EndIf
; Write the new value to the registry
Local $RegWrite = RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoDrives", "REG_DWORD", $NewMask)
If @error Then
_Log("Error: Could not hide drive " & $DriveLetter & ": in Explorer. Mask: " & $NewMask & " Error: " & @error & " Result: " & $RegWrite)
Else
_Log("Success: " & ($Hide ? "Hid" : "Unhid") & " drive " & $DriveLetter & ": in Explorer.")
EndIf
EndFunc ;==>_HideDrive
;===============================================================================
; Function Name: _TextBox
; Description: Creates a text box with a label and OK/Cancel buttons
; Call With: _TextBox($Title, $Label, $Text = "", $Width = Default, $Height = Default, $Left = Default, $Top = Default, $Timeout = 0, $HWND = Default)
; Parameter(s): $Title - Title of the GUI
; $Label - Label of the text box
; $Text - Text to display in the text box
; $Width - Width of the GUI
; $Height - Height of the GUI
; $Left - Left position of the GUI
; $Top - Top position of the GUI
; $Timeout - Timeout in seconds
; $HWND - Handle of the parent window
; Return Value(s): On Success - Text from the text box
; On Failure - 0
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 11/01/2025 -- v1.0
;===============================================================================
Func _TextBox($Title, $Label, $Text = "", $Width = Default, $Height = Default, $Left = Default, $Top = Default, $Timeout = 0, $HWND = Default)
If $Width = Default Then $Width = 300
If $Height = Default Then $Height = 200
If $Left = Default Then $Left = -1
If $Top = Default Then $Top = -1
If $Timeout = Default Then $Timeout = 0
Local $hGUI = GUICreate($Title, $Width, $Height, $Left, $Top, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), Default, $HWND)
Local $hLabel = GUICtrlCreateLabel($Label, 10, 10)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
Local $hEdit = GUICtrlCreateEdit($Text, 10, 30, $Width - 20, $Height - 70, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
Local $hOK = GUICtrlCreateButton("OK", $Width - 170, $Height - 32, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
Local $hCancel = GUICtrlCreateButton("Cancel", $Width - 85, $Height - 32, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
GUICtrlSetCursor($hEdit, -1)
GUISetState(@SW_SHOW)
ControlSend($hGUI, "", $hEdit, "{LEFT}")
While 1
Local $GUIEvent = GUIGetMsg()
Switch $GUIEvent
Case $GUI_EVENT_CLOSE, $hCancel
GUIDelete($hGUI)
Return SetError(1, 0, 0)
Case $hOK
Local $ReturnText = GUICtrlRead($hEdit)
GUIDelete($hGUI)
Return SetError(0, 0, $ReturnText)
EndSwitch
Sleep(10)
WEnd
EndFunc ;==>_TextBox
;===============================================================================
; Function Name: _Error
; Description: Call _log and MsgBox in one command
; Call With: _Error($Title, $Message[, $iLevel = Default[, $MessageEx = ""]])
; Parameter(s): $Title - Window title
; $Message - Message for MsgBox and _Log.
; $iLevel - [optional]
; $MessageEx - [optional] an extra message that will only show in the log.
; Return Value(s): MsgBox return value
; Author(s): JohnMC - JohnsCS.com
;===============================================================================
Func _Error($Title, $Message, $iLevel = Default, $MessageEx = "")
If $MessageEx <> "" Then $MessageEx = " - " & $MessageEx
_Log($Message & $MessageEx, $iLevel)
Return MsgBox(16, $Title, $Message)
EndFunc ;==>_Error
;===============================================================================
; Function Name: _RandomString
; Description: Generates a random string of characters (numbers and letters by default)
; Call With: _RandomString($Min, $Max[, $Chars = Default])
; Parameter(s): $Min - Minimum string length
; $Max - Maximum string length
; $Chars - [optional] String of characters to choose from. Default is all numbers and letters (upper and lower)
; Return Value(s): A random string of characters
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 5/11/2024 -- v1.0
;===============================================================================
Func _RandomString($iMin, $iMax, $sChars = Default)
If $sChars = Default Then $sChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
Local $sReturn, $aChars = StringSplit($sChars, '')
For $i = 1 To Random($iMin, $iMax, 1)
$sReturn &= $aChars[Random(1, $aChars[0], 1)]
Next
Return $sReturn
EndFunc ;==>_RandomString
;===============================================================================
; Function Name: _ListSelect
; Description: Creates a list select box
; Call With: _ListSelect($aList[, $sTitle[, $sMessage[, $iDefaultIndex[, $sIcon[, $iWidth[, $iHeight]]]]]])
; Parameter(s): $aList - Array of items to display
; $sTitle - [optional] Window title
; $sMessage - [optional] Label text
; $iDefaultIndex - [optional] Default selected index (default 1)
; $sIcon - [optional] Icon file and ID (e.g. "shell32.dll,1")
; $iWidth - [optional] Window width (default 400)
; $iHeight - [optional] Window height (default 175)
; Return Value(s): The text of the selected item, @extended contains the index of the selected item
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 04/24/2024
;===============================================================================
Func _ListSelect($aList, $sTitle = "", $sMessage = "", $iDefaultIndex = 1, $sIcon = "", $iWidth = 400, $iHieght = 175)
Local $IconFile = StringLeft($sIcon, StringInStr($sIcon, ",", 0, -1) - 1)
Local $IconID = Number(StringTrimLeft($sIcon, StringInStr($sIcon, ",", 0, -1)))
Local $ListSelectGUI = GUICreate($sTitle, $iWidth, $iHieght, -1, -1)
Local $ListSelectList1 = GUICtrlCreateList("", 70, 48, $iWidth - 90, $iHieght - 90, -1, 0)
Local $ListSelectIcon1 = GUICtrlCreateIcon($IconFile, $IconID, 20, 64, 32, 32)
Local $ListSelectLabel1 = GUICtrlCreateLabel($sMessage, 20, 10, $iWidth - 50, 30)
Local $ListSelectCancel = GUICtrlCreateButton("Cancel", 304, 140, 75, 25)
Local $ListSelectOK = GUICtrlCreateButton("OK", 216, 140, 75, 25)
GUISetIcon($IconFile, $IconID)
GUISetState(@SW_SHOW)
For $i = UBound($aList) - 1 To 1 Step -1
GUICtrlSetData($ListSelectList1, $aList[$i])
Next
_GUICtrlListBox_SelectString($ListSelectList1, $aList[$iDefaultIndex])
Local $ListSelectGUIMsg
While 1
$ListSelectGUIMsg = GUIGetMsg()
Switch $ListSelectGUIMsg
Case $GUI_EVENT_CLOSE, $ListSelectCancel
GUIDelete($ListSelectGUI)
Return SetError(1, 0, 0)
Case $ListSelectOK
Local $ReturnIndex = _GUICtrlListBox_GetCurSel($ListSelectList1)
Local $ReturnText = _GUICtrlListBox_GetText($ListSelectList1, $ReturnIndex)
GUIDelete($ListSelectGUI)
Return SetError(0, $ReturnIndex, $ReturnText)
EndSwitch
Sleep(10)
WEnd
EndFunc ;==>_ListSelect
;===============================================================================
; Function Name: _Timer
; Description: Creates a quick to use timer
; Call With: _Timer([$Reset = True])
; Parameter(s): $Reset - [optional] If True, time will reset
; Return Value(s): The time in miliseconds since last reset or init
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 03/14/2024 -- v1.0
;===============================================================================
Func _Timer($Reset = True)
If Not IsDeclared("_Timer_Handle") Then
Global $_Timer_Handle
$_Timer_Handle = TimerInit()
Return True
EndIf
Local $Return = Round(TimerDiff($_Timer_Handle), 1)
If $Reset Then $_Timer_Handle = TimerInit()
Return $Return
EndFunc ;==>_Timer
;===============================================================================
; Function Name: _GetVisibleWindows
; Description: Get an array of information for visible windows
; Call With: _GetVisibleWindows([$GetText = False])
; Parameter(s): $GetText - [optional] True/False - Get window text (slow)
; Return Value(s): 2D Array of windows and window information
; [0][0] contains the number of windows
; Author(s): JohnMC - JohnsCS.com, based on AdamUL's _GetVisibleWindows
; Date/Version: 03/29/2024 -- v2.1
;===============================================================================
Func _GetVisibleWindows($GetText = False)
Local $NewCol, $TotalTime, $Timer
Local $TotalTime = TimerInit()
; 0,1 Retrieve a list of windows
Local $aWinList = WinList()
If Not IsArray($aWinList) Then Return SetError(0, 0, 0)
$aWinList[0][1] = "WinHandle"
; Resize Array
ReDim $aWinList[UBound($aWinList) + 1][14 + 1]
; 2 Add window states
$NewCol = 2
$aWinList[0][$NewCol] = "State"
For $i = 1 To $aWinList[0][0]
$aWinList[$i][$NewCol] = WinGetState($aWinList[$i][1])
Next
; 3 Add state descriptions
Local $WindowStateIndex = 2
$NewCol = 3
$aWinList[0][$NewCol] = "StateDesc"
For $i = 1 To $aWinList[0][0]
Local $Desc = ""
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_EXISTS) Then $Desc &= "Exists"
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_VISIBLE) Then $Desc &= "Visible"
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_ENABLED) Then $Desc &= "Enabled"
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_ACTIVE) Then $Desc &= "Active"
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_MINIMIZED) Then $Desc &= "Minimized"
If BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_MAXIMIZED) Then $Desc &= "Maximized"
$aWinList[$i][$NewCol] = $Desc
Next
; Delete undesirable windows
Local $WindowStateIndex = 2
Local $aNewWinList[0][UBound($aWinList, 2)]
Local $NewIndex = 0
For $i = 0 To $aWinList[0][0]
If $i <> 0 And ($aWinList[$i][0] = "" Or Not BitAND($aWinList[$i][$WindowStateIndex], $WIN_STATE_VISIBLE)) Then ContinueLoop
ReDim $aNewWinList[$NewIndex + 1][UBound($aWinList, 2)]
For $b = 0 To UBound($aWinList, 2) - 1
$aNewWinList[$NewIndex][$b] = $aWinList[$i][$b]
Next
$NewIndex += 1
Next
$aNewWinList[0][0] = UBound($aNewWinList) - 1
$aWinList = $aNewWinList
; 4 Get Process ID (PID) and add to the array.
$NewCol = 4
$aWinList[0][$NewCol] = "PID"
For $i = 1 To $aWinList[0][0]
$aWinList[$i][$NewCol] = WinGetProcess($aWinList[$i][1])
Next
; 5 Add process name
Local $PIDIndex = 4
$NewCol = 5
$aWinList[0][$NewCol] = "Name"
Local $aProcessList = ProcessList()
For $i = 1 To $aWinList[0][0]
For $b = 1 To UBound($aProcessList) - 1
If $aProcessList[$b][1] = $aWinList[$i][$PIDIndex] Then
$aWinList[$i][$NewCol] = $aProcessList[$b][0]
EndIf
Next
Next
; 6 Add path using winapi method
$NewCol = 6
$aWinList[0][$NewCol] = "Path"
For $i = 1 To $aWinList[0][0]
Local $Path = _WinAPI_GetProcessFileName($aWinList[$i][4])
; No path might mean the process is elevated so let's try some other things...
If $Path = "" Then
; Might only help if the stars align
Local $aEnum = _WinAPI_EnumProcessModules($aWinList[$i][4])
If Not @error And UBound($aEnum) >= 2 Then
$TestPath = $aEnum[1]
; The exe might be in the system folder (elevated cmd or task manager)
Else
$TestPath = @SystemDir & "\" & $aWinList[$i][5]
EndIf
$TestFileAttrib = FileGetAttrib($TestPath)
If Not @error And Not StringInStr($TestFileAttrib, "D") Then $Path = $TestPath
EndIf
$aWinList[$i][$NewCol] = $Path
Next
; 7 Add command line string
$NewCol = 7
$aWinList[0][$NewCol] = "Command"
For $i = 1 To $aWinList[0][0]
$aWinList[$i][$NewCol] = _WinAPI_GetProcessCommandLine($aWinList[$i][4])
Next
; 8 Add window position and size
; -3200,-3200 is minimized window
; -8,-8 is maximized window on 1st display, and x,-8 is maximized window on the nth display were x is the nth display width plus -8 (W + -8).
$NewCol = 8
$aWinList[0][$NewCol] = "Position"
For $i = 1 To $aWinList[0][0]
Local $aWinPosSize = WinGetPos($aWinList[$i][1])
If Not @error Then
$aWinList[$i][$NewCol] = $aWinPosSize[0] & "," & $aWinPosSize[1] & "," & $aWinPosSize[2] & "," & $aWinPosSize[3]
EndIf
Next
; 9,10 Add window style and exstyle
$NewCol = 9
$aWinList[0][$NewCol] = "Style"
$NewCol2 = 10
$aWinList[0][$NewCol2] = "ExStyle"
For $i = 1 To $aWinList[0][0]
Local $tWINDOWINFO = _WinAPI_GetWindowInfo($aWinList[$i][1])
$aWinList[$i][$NewCol] = DllStructGetData($tWINDOWINFO, 'Style', 1)
$aWinList[$i][$NewCol2] = DllStructGetData($tWINDOWINFO, 'ExStyle', 1)
Next
; 11 Add style descriptions
Local $StyleIndex = 9
$NewCol = 11
$aWinList[0][$NewCol] = "StyleDesc"
For $i = 1 To $aWinList[0][0]
Local $Desc = ""
If BitAND($aWinList[$i][$StyleIndex], $WS_BORDER) Then $Desc &= "Border"
If BitAND($aWinList[$i][$StyleIndex], $WS_POPUP) Then $Desc &= "Popup"
If BitAND($aWinList[$i][$StyleIndex], $WS_SYSMENU) Then $Desc &= "Sysmenu"
If BitAND($aWinList[$i][$StyleIndex], $WS_GROUP) Then $Desc &= "Group"
If BitAND($aWinList[$i][$StyleIndex], $WS_SIZEBOX) Then $Desc &= "Sizebox"
If BitAND($aWinList[$i][$StyleIndex], $WS_CHILD) Then $Desc &= "Child"
If BitAND($aWinList[$i][$StyleIndex], $WS_DLGFRAME) Then $Desc &= "Dialog"
If BitAND($aWinList[$i][$StyleIndex], $WS_MINIMIZEBOX) Then $Desc &= "Minbox"
If BitAND($aWinList[$i][$StyleIndex], $WS_MAXIMIZEBOX) Then $Desc &= "Maxbox"
If BitAND($aWinList[$i][$StyleIndex], $WS_CAPTION) Then $Desc &= "Caption"
If BitAND($aWinList[$i][$StyleIndex], $WS_CLIPCHILDREN) Then $Desc &= "Clipchildren"
If BitAND($aWinList[$i][$StyleIndex], $WS_CLIPSIBLINGS) Then $Desc &= "Clipsiblings"
If BitAND($aWinList[$i][$StyleIndex], $WS_DISABLED) Then $Desc &= "Disabled"
If BitAND($aWinList[$i][$StyleIndex], $WS_HSCROLL) Then $Desc &= "Hscroll"
If BitAND($aWinList[$i][$StyleIndex], $WS_MAXIMIZE) Then $Desc &= "Maximize"
If BitAND($aWinList[$i][$StyleIndex], $WS_OVERLAPPEDWINDOW) Then $Desc &= "Overlappedwindow"
If BitAND($aWinList[$i][$StyleIndex], $WS_POPUPWINDOW) Then $Desc &= "Popupwindow"
If BitAND($aWinList[$i][$StyleIndex], $DS_MODALFRAME) Then $Desc &= "Modalframe"
If BitAND($aWinList[$i][$StyleIndex], $DS_SETFOREGROUND) Then $Desc &= "Setforeground"
If BitAND($aWinList[$i][$StyleIndex], $WS_TABSTOP) Then $Desc &= "Tabstop"
$aWinList[$i][$NewCol] = $Desc
Next
; 12 Add ExStyle descriptions
Local $ExStyleIndex = 10
$NewCol = 12
$aWinList[0][$NewCol] = "ExStyleDesc"
For $i = 1 To $aWinList[0][0]
Local $Desc = ""
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_TOOLWINDOW) Then $Desc &= "Tool"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_TOPMOST) Then $Desc &= "Top"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_CONTROLPARENT) Then $Desc &= "Parent"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_APPWINDOW) Then $Desc &= "App"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_MDICHILD) Then $Desc &= "Child"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_DLGMODALFRAME) Then $Desc &= "Dialogframe"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_ACCEPTFILES) Then $Desc &= "Acceptfiles"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_CLIENTEDGE) Then $Desc &= "Clientedge"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_COMPOSITED) Then $Desc &= "Composited"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_LAYERED) Then $Desc &= "Layered"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_WINDOWEDGE) Then $Desc &= "Windowedge"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_STATICEDGE) Then $Desc &= "Staticedge"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_PALETTEWINDOW) Then $Desc &= "Palettewindow"
If BitAND($aWinList[$i][$ExStyleIndex], $WS_EX_NOACTIVATE) Then $Desc &= "Noactivate"
$aWinList[$i][$NewCol] = $Desc
Next
; 13 Get Arch
$NewCol = 13
$aWinList[0][$NewCol] = "Arch"
For $i = 1 To $aWinList[0][0]
Local $sArch
If _WinAPI_GetBinaryType($aWinList[$i][6]) = 1 Then
Switch @extended
Case $SCS_32BIT_BINARY
$sArch = "32-bit"
Case $SCS_64BIT_BINARY
$sArch = "64-bit"
Case $SCS_DOS_BINARY
$sArch = "DOS"
Case $SCS_WOW_BINARY
$sArch = "16-bit"
EndSwitch
EndIf
$aWinList[$i][$NewCol] = $sArch
Next
; 14 Get Window's text and add to the array.
$NewCol = 14
$aWinList[0][$NewCol] = "Text"
If $GetText Then
Local $WinDetectHiddenText = Opt("WinDetectHiddenText")
Opt("WinDetectHiddenText", 1)
For $i = 1 To $aWinList[0][0]
$aWinList[$i][$NewCol] = WinGetText($aWinList[$i][1])
Next
Opt("WinDetectHiddenText", $WinDetectHiddenText)
EndIf
Return SetError(0, TimerDiff($TotalTime), $aWinList)
EndFunc ;==>_GetVisibleWindows
;===============================================================================
; Function Name: IsActivated
; Description: Check Windows activation status
; Call With: IsActivated()
; Parameter(s): None
; Return Value(s): A string with the activation status
; @error will be true if activation status could not be retrieved
; @extended will be 0 for activated and >0 for not activated
; Author(s): AutoIT Forum, modified by JohnMC - JohnsCS.com
; Date/Version: 03/02/2024 -- v1.1
;===============================================================================
Func IsActivated()
$oWMIService = ObjGet("winmgmts:\\.\root\cimv2")
If Not IsObj($oWMIService) Then Return SetError(1, 0, "WMI Object Error")
$oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM SoftwareLicensingProduct WHERE PartialProductKey <> null")
If Not IsObj($oCollection) Then Return SetError(2, 0, "WMI Query Error")
For $oItem In $oCollection
Switch $oItem.LicenseStatus
Case 0
Return SetError(0, 1, "Unlicensed")
Case 1
If $oItem.GracePeriodRemaining Then
If StringInStr($oItem.Description, "TIMEBASED_") Then
Return SetError(0, 0, "Timebased activation will expire in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
Else
Return SetError(0, 0, "Volume activation will expire in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
EndIf
Else
Return SetError(0, 0, "The machine is permanently activated.")
EndIf
Case 2
Return SetError(0, 2, "Initial grace period ends in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
Case 3
Return SetError(0, 3, "Additional grace period ends in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
Case 4
Return SetError(0, 4, "Non-genuine grace period ends in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
Case 5
Return SetError(0, 5, "Windows is in Notification mode")
Case 6
Return SetError(0, 6, "Extended grace period ends in " & Round($oItem.GracePeriodRemaining / 60 / 24, 1) & " days")
Case Else
Return SetError(4, 7, "Unknown Status Code")
EndSwitch
Next
Return SetError(3, 0, "Unknown Error")
EndFunc ;==>IsActivated
;===============================================================================
; Function Name: _FileModifiedAge
; Description: Get the age of a file based on its last modified time
; Call With: _FileModifiedAge($sFile)
; Parameter(s): $sFile - Path to a file
; Return Value(s): File age in miliseconds
; Author(s): AutoIT Forum, modified by JohnMC - JohnsCS.com
; Date/Version: 11/15/2023 -- v1.1
;===============================================================================
Func _FileModifiedAge($sFile)
Local $hFile = _WinAPI_CreateFile($sFile, 2, 2)
If $hFile = 0 Then
Return SetError(1, 0, -1)
Else
Local $tFileTime = _Date_Time_GetFileTime($hFile)
Local $aFileTime = _Date_Time_FileTimeToArray($tFileTime[2])
Local $sFileTime = _Date_Time_FileTimeToStr($tFileTime[2], 1)
_WinAPI_CloseHandle($hFile)
Local $tSystemTime = _Date_Time_GetSystemTime()
Local $sSystemTime = _Date_Time_SystemTimeToDateTimeStr($tSystemTime, 1)
Local $aSystemTime = _Date_Time_SystemTimeToArray($tSystemTime)
Local $iFileAge = _DateDiff('s', $sFileTime, $sSystemTime) * 1000 + $aSystemTime[6] - $aFileTime[6]
Return $iFileAge
EndIf
EndFunc ;==>_FileModifiedAge
;===============================================================================
; Function Name: _WMI
; Description: Run a WMI query with the option of returning the first object (default) or all objects
; Call With: _WMI($Query[, $Single = True])
; Parameter(s): $Query - WMI query string
; $Single - [optional] Return the first object, Default is True.
; Return Value(s): Object(s)
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 11/15/2023 -- v1.1
;===============================================================================
Func _WMI($Query, $Single = True)
If Not IsDeclared("_objWMIService") Then
Local $Object = ObjGet("winmgmts:\\.\root\CIMV2")
If @error Or Not IsObj($Object) Then Return SetError(1, 0, 0)
Global $_objWMIService = $Object
EndIf
Local $colItems = $_objWMIService.ExecQuery($Query)
If @error Or Not IsObj($colItems) Then Return SetError(2, 0, 0)
If $Single Then
Local $objItem
For $objItem In $colItems
Return $objItem
Next
Else
Return $colItems
EndIf
EndFunc ;==>_WMI
;===============================================================================
; Function Name: _INetSmtpMailCom
; Description: Send an email using a Windows API with authentication and encryption
; Call With: _INetSmtpMailCom($sSMTPServer, $sFromName, $sFromAddress, $sToAddress[, ...])
; Parameter(s): $sSMTPServer - SMTP server address
; $sFromName - Sender display name
; $sFromAddress - Sender email address
; $sToAddress - Recipient email address
; $sSubject - [optional] Email subject
; $sBody - [optional] Email body
; $sUsername - [optional] SMTP username
; $sPassword - [optional] SMTP password
; $sCCAddress - [optional] CC address
; $sBCCAddress - [optional] BCC address
; $iPort - [optional] Port, default 587
; $bSSL - [optional] Use SSL, default False
; $bTLS - [optional] Use TLS, default True
; Return Value(s): None
; Author(s): AutoIT Forum, modified by JohnMC - JohnsCS.com
; Date/Version: 11/15/2023 -- v1.1
;===============================================================================
Func _INetSmtpMailCom($sSMTPServer, $sFromName, $sFromAddress, $sToAddress, $sSubject = "", $sBody = "", $sUsername = "", $sPassword = "", $sCCAddress = "", $sBCCAddress = "", $iPort = 587, $bSSL = False, $bTLS = True)
Local $oMail = ObjCreate("CDO.Message")
$oMail.From = '"' & $sFromName & '" <' & $sFromAddress & '>'
$oMail.To = $sToAddress
$oMail.Subject = $sSubject
If $sCCAddress Then $oMail.Cc = $sCCAddress
If $sBCCAddress Then $oMail.Bcc = $sBCCAddress
If StringInStr($sBody, "<") And StringInStr($sBody, ">") Then
$oMail.HTMLBody = $sBody
Else
$oMail.Textbody = $sBody & @CRLF
EndIf
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $sSMTPServer
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $iPort
; Authenticated SMTP
If $sUsername <> "" Then
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $sUsername
$oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $sPassword
EndIf
; Set security parameters
If $bSSL Then $oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
If $bTLS Then $oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendtls") = True
; Update settings
$oMail.Configuration.Fields.Update
$oMail.Fields.Update
; Send the Message
$oMail.Send
If @error Then Return SetError(2, 0, 0)
$oMail = ""
EndFunc ;==>_INetSmtpMailCom
;===============================================================================
; Function Name: _StringExtract
; Description: Extract a string between two search strings
; Call With: _StringExtract($sString, $sStartSearch, $sEndSearch[, $iStartTrim[, $iEndTrim]])
; Parameter(s): $sString - String to extract from
; $sStartSearch - Start search string
; $sEndSearch - End search string
; $iStartTrim - [optional] Start trim characters
; $iEndTrim - [optional] End trim characters
; Return Value(s): Extracted string
; Author(s): JohnMC - JohnsCS.com
; Date/Version: Unknown -- v1.0
; 11/01/2025 -- v1.1 Refactor, local variables
;===============================================================================
Func _StringExtract($sString, $sStartSearch, $sEndSearch, $iStartTrim = 0, $iEndTrim = 0)
Local $iStartPos = StringInStr($sString, $sStartSearch)
If Not $iStartPos Then Return SetError(1, 0, 0)
$iStartPos = $iStartPos + StringLen($sStartSearch)
Local $iCount = StringInStr($sString, $sEndSearch, 0, 1, $iStartPos)
If Not $iCount Then Return SetError(2, 0, 0)
$iCount = $iCount - $iStartPos
Return StringMid($sString, $iStartPos + $iStartTrim, $iCount + $iEndTrim - $iStartTrim)
EndFunc ;==>_StringExtract
;===============================================================================
; Function Name: __StringProper
; Description: Modified version of _StringProper to lowercase after common contractions
; Call With: __StringProper($sString)
; Parameter(s): $sString - String to properly capitalize
; Return Value(s): On Success - Properly capitalized string
; On Failure - Empty string
; Author(s): Jos van der Zande <jdeb at autoitscript dot com>
; JohnMC - JohnsCS.com
; Date/Version: 10/15/2014 -- v1.0
; 11/01/2025 -- v1.1 Refactor, match on next two characters
;===============================================================================
Func __StringProper($sString)
Local $bCapNext = True, $sChr = "", $sReturn = ""
Local $sPattern = '[a-zA-ZÀ-ÿšœžŸ]'
Local $iStringLength = StringLen($sString)
For $i = 1 To $iStringLength
$sChr = StringMid($sString, $i, 1)
$sNextTwo = StringMid($sString, $i + 1, 2)
Select
Case $bCapNext = True
If StringRegExp($sChr, $sPattern) Then
$sChr = StringUpper($sChr)
$bCapNext = False
EndIf
Case $sChr = "'"
Switch $sNextTwo
Case "s ", "t ", "m ", "d ", "re ", "ve", "ll"
$sChr = StringUpper($sChr)
$bCapNext = False
Case Else
$bCapNext = True
EndSwitch
Case Not StringRegExp($sChr, $sPattern)
$bCapNext = True
Case Else
$sChr = StringLower($sChr)
EndSelect
$sReturn &= $sChr
Next
Return $sReturn
EndFunc ;==>__StringProper
;===============================================================================
; Function Name: _FileInUse()
; Description: Checks if file is in use
; Call With: _FileInUse($sFilename, $iAccess = 0)
; Parameter(s): $sFilename = File name
; $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode
; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file,
; fails if file open in readonly mode by app
; Return Value(s): 1 - file in use (@error contains system error code)
; 0 - file not in use
; -1 dllcall error (@error contains dllcall error code)
; Author(s): Siao, rover
; Date/Version: 10/15/2014 -- v1.0
;===============================================================================
Func _FileInUse($sFilename, $iAccess = 0)
Local $aRet, $hFile, $iError, $iDA
Local Const $GENERIC_WRITE = 0x40000000
Local Const $GENERIC_READ = 0x80000000
Local Const $FILE_ATTRIBUTE_NORMAL = 0x80
Local Const $OPEN_EXISTING = 3
$iDA = $GENERIC_READ
If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE)
$aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _
"str", $sFilename, _ ;lpFileName
"dword", $iDA, _ ;dwDesiredAccess
"dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE
"dword", 0x00000000, _ ;lpSecurityAttributes = NULL
"dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING
"dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
"hwnd", 0) ;hTemplateFile = NULL
$iError = @error
If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1)
$hFile = $aRet[0]
If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1
$aRet = DllCall("Kernel32.dll", "int", "GetLastError")
;ERROR_SHARING_VIOLATION = 32 0x20
;The process cannot access the file because it is being used by another process.
If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1)
Return SetError($aRet[0], 0, 1)
Else
;close file handle
DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
Return SetError(@error, 0, 0)
EndIf
EndFunc ;==>_FileInUse
;===============================================================================
; Function Name: _FileInUseWait
; Description: Waits for a file to be released (no open handles)
; Call With: _FileInUseWait($sFilePath[, $Timeout = 0[, $Sleep = 2000]])
; Parameter(s): $sFilePath - Path to the file to check
; $Timeout - [optional] Seconds before giving up (0 = wait forever)
; $Sleep - [optional] Milliseconds between checks (default 2000)
; Return Value(s): On Success - 1 (file is available)
; On Failure - 0 (timeout)
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 10/15/2014 -- v1.0
;===============================================================================
Func _FileInUseWait($sFilePath, $Timeout = 0, $Sleep = 2000)
$Timeout = $Timeout * 1000
$Time = TimerInit()
While 1
If _FileInUse($sFilePath) Then
_Log(" File locked")
Else
Return 1
EndIf
If $Timeout > 0 And $Timeout < TimerDiff($Time) Then
_Log(" Timeout, file locked")
Return 0
EndIf
Sleep($Sleep)
WEnd
EndFunc ;==>_FileInUseWait
;===============================================================================
; Function Name: _RunWait
; Description: Run a program and wait for it to finish, capturing stdout/stderr
; Call With: _RunWait($sProgram[, $Working[, $Show[, $Opt[, $Live[, $Diag]]]]])
; Parameter(s): $sProgram - Command line to run
; $Working - [optional] Working directory
; $Show - [optional] Window show flag (default @SW_HIDE)
; $Opt - [optional] Stdout/stderr option (default $STDERR_MERGED)
; $Live - [optional] Log output in real-time (default False)
; $Diag - [optional] Diagnostic mode for line endings (default False)
; Return Value(s): On Success - Captured stdout/stderr data, @extended = PID
; On Failure - 0
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 01/16/2016 -- v1.1
;===============================================================================
Func _RunWait($sProgram, $Working = "", $Show = Default, $Opt = Default, $Live = False, $Diag = False)
Local $sData, $iPid
If $Show = Default Then $Show = @SW_HIDE
If $Opt = Default Then $Opt = $STDERR_MERGED
$iPid = Run($sProgram, $Working, $Show, $Opt)
If @error Then
_Log("_RunWait: Couldn't Run " & $sProgram)
Return SetError(1, 0, 0)
EndIf
$sData = _ProcessWaitClose($iPid, $Live, $Diag)
Return SetError(0, $iPid, $sData)
EndFunc ;==>_RunWait
;===============================================================================
; Function Name: _ProcessWaitClose
; Description: Wait for a process to close while capturing its stdout/stderr output
; Call With: _ProcessWaitClose($iPid[, $Live = False[, $Diag = False]])
; Parameter(s): $iPid - PID of the process (must have been started with stdout/stderr flags)
; $Live - [optional] Log output lines in real-time (default False)
; $Diag - [optional] Show line ending diagnostics (default False)
; Return Value(s): Captured stdout/stderr data as a string
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 09/8/2023 -- v1.3
;===============================================================================
Func _ProcessWaitClose($iPid, $Live = Default, $Diag = Default)
Local $sData, $sStdRead
If $Live = Default Then $Live = False
If $Diag = Default Then $Diag = False
While 1
$sStdRead = StdoutRead($iPid)
If @error Or $sStdRead = "" Then StderrRead($iPid)
If @error And Not ProcessExists($iPid) Then ExitLoop
$sStdRead = StringReplace($sStdRead, @CR & @LF & @CR & @LF, @CR & @LF)
If $Diag Then
$sStdRead = StringReplace($sStdRead, @CRLF, "_@CRLF")
$sStdRead = StringReplace($sStdRead, @CR, "@CR" & @CR)
$sStdRead = StringReplace($sStdRead, @LF, "@LF" & @LF)
$sStdRead = StringReplace($sStdRead, "_@CRLF", "@CRLF" & @CRLF)
EndIf
If $sStdRead <> @CRLF Then
$sData &= $sStdRead
If $Live And $sStdRead <> "" Then
If StringRight($sStdRead, 2) = @CRLF Then $sStdRead = StringTrimRight($sStdRead, 2)
If StringRight($sStdRead, 1) = @LF Then $sStdRead = StringTrimRight($sStdRead, 1)
_Log($sStdRead)
EndIf
EndIf
Sleep(5)
WEnd
Return $sData
EndFunc ;==>_ProcessWaitClose
;===============================================================================
; Function Name: _StringStripWS()
; Description: Strips all white space chars, excluding char(32) (the regular space)
; Call With: _StringStripWS($String)
; Parameter(s): $String - String To Strip
; Return Value(s): On Success - Striped String
; On Failure - Full String
; Author(s): JohnMC - JohnsCS.com
; Date/Version: 01/29/2010 -- v1.0
;===============================================================================
Func _StringStripWS($String)
Return StringRegExpReplace($String, "[" & Chr(0) & Chr(9) & Chr(10) & Chr(11) & Chr(12) & Chr(13) & "]", "")
EndFunc ;==>_StringStripWS
;===============================================================================
; Function Name: _MouseCheck()
; Description: Checks for mouse movement