Leaderboard
Popular Content
Showing content with the highest reputation on 12/01/2024 in all areas
-
@CYCho today I was able to test your 1st script at my brother's home (Win11 x64) Here is the display on his computer, using charset 129 : ... _GUICtrlRichEdit_SetFont($hRichEdit, 14, "Arial", 129) ; $HANGEUL_CHARSET = 129 _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "1. This is text" & @CRLF & "2. ▶/❚❚ This is more text") ... So the 2nd "This is more text" appears bolder compared to the 1st one (as you noticed) IIRC charset 130 (the Korean $JOHAB_CHARSET) displayed same as 129 And when no charset parameter was set, then both "This is more text" looked same. For what it's worth...1 point
-
RegEx a function with its parameters
ioa747 reacted to argumentum for a topic
; looking to discern the parameters with RegExp ConsoleWriteDebug(anyFunc(' ''1''', "2""", @ScriptLineNumber) & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug('This, is'' a string' & @CRLF) ; add @ScriptLineNumber Func anyFunc($1 = "", $2 = "", $3 = "") Return 'anyFunc' & $1 & $2 & $3 EndFunc ;==>anyFunc Nice @ioa747. I bet you removed anyFunc() because it wasn't there ( in the 1st post ), or didn't refresh this posting's page. In any case, in a ConsoleWrite() when you run a function inside and you'd wanna see the function's output your current code brakes the output script. I do that ( run func() inside a ConsoleWrite() ) a lot. I was adding stuff as I went along, looking to brake the code with less than ideal circumstances, like having commas or parenthesis or some other character that would confuse the function that adds the @ScriptLineNumber to the script.1 point -
RegEx a function with its parameters
argumentum reacted to ioa747 for a topic
; looking to discern the parameters with RegExp ConsoleWriteDebug(anyFunc(' ''1''', "2""", @ScriptLineNumber) & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug('This, is'' a string' & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug("This, is' a string" & @CRLF) ; add @ScriptLineNumber ConsoleWriteDebug('This, is'' a string' & @CRLF, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug("This, is' a string" & @CRLF, 88, 1, 2) ; don't add @ScriptLineNumber ;~ ConsoleWriteDebug("This is' a string" & @CRLF, @ScriptLineNumber, 1, 2) ; don't touch Local $sString = "This is' a string" ConsoleWriteDebug($sString & @CRLF, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug($sString, @ScriptLineNumber) ; don't add @ScriptLineNumber ConsoleWriteDebug($sString) ; add @ScriptLineNumber ConsoleWrite(@CRLF & _Add_ScriptLineNumber(FileRead(@ScriptFullPath)) & @CRLF) Func _Add_ScriptLineNumber00($sScript, $sFuncName = "ConsoleWriteDebug", $iAddAtParameterNumber = 2) Local $aRegex, $iPos, $aScript = StringSplit($sScript, @CRLF, 1) $sScript = "" Local $i_Base, $i_apostrophe_1, $i_quotation_1, $i_comma_1 For $n = 1 To UBound($aScript) - 1 If StringInStr($aScript[$n], 'Func ConsoleWriteDebug(') Or _ Not StringInStr($aScript[$n], 'ConsoleWriteDebug(') Or _ StringInStr($aScript[$n], ';') < StringInStr($aScript[$n], 'ConsoleWriteDebug(') Then $sScript &= $aScript[$n] & @CRLF ContinueLoop EndIf $aRegex = StringRegExp($aScript[$n], 'ConsoleW' & 'riteDebug\(.*\)', 1) If UBound($aRegex) <> 1 Then $sScript &= $aScript[$n] & @CRLF ContinueLoop EndIf ConsoleWrite('- >' & '' & '<' & @TAB & $i_apostrophe_1 & @TAB & $i_quotation_1 & @TAB & $i_comma_1 & @CRLF) ConsoleWrite('@@ RegEx (' & $n & ') : ' & $aRegex[0] & @CRLF) $sRegex = StringTrimRight(StringReplace($aRegex[0], 'ConsoleWriteDebug(', ''), 1) $sSpecialChr = StringLeft($sRegex, 1) $aStringSplitSV = _StringSplitSV($sRegex, ",", $sSpecialChr) If UBound($aStringSplitSV) = 1 Then Switch $sSpecialChr Case '"', "'" $sScript &= StringReplace($aScript[$n], $aRegex[0], 'ConsoleWriteDebug(' & $aStringSplitSV[0] & ', @ScriptLineNumber)') & " ;;; DONE ;;;" & @CRLF Case Else $sScript &= $aScript[$n] & ' ;;; need to discern ;;;' & @CRLF EndSwitch ElseIf UBound($aStringSplitSV) > 1 Then $sScript &= $aScript[$n] & ' ;;; leave as is ;;;' & @CRLF Else $sScript &= $aScript[$n] & ' ;;; no clue ;;;' & @CRLF EndIf For $m = 0 To UBound($aStringSplitSV) - 1 ConsoleWrite('>' & $m & @TAB & $aStringSplitSV[$m] & @CRLF) Next Next Return $sScript ; with the added ", @ScriptLineNumber)" where needed EndFunc ;==>_Add_ScriptLineNumber Func ConsoleWriteDebug($sStr = @CRLF, $iLine = @ScriptLineNumber, $iError = @error, $iExtended = @extended) Local $iRet = ConsoleWrite("@@ Debug (" & $iLine & ") : " & $sStr & (StringRight($sStr, 2) = @CRLF ? "" : @CRLF)) Return SetError($iError, $iExtended, $iRet) ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1538974 EndFunc ;==>ConsoleWriteDebug Func anyFunc($1 = "", $2 = "", $3 = "") Return 'anyFunc' & $1 & $2 & $3 EndFunc ;==>anyFunc Func _StringSplitSV($sString, $sSepChr = ",", $sSpecialChr = '"') ; https://www.autoitscript.com/forum/topic/105756-string-split-escapeignore-quoted-delimiters/?do=findComment&comment=747333 Return StringRegExp($sString, "\G(?:\Q" & $sSepChr & "\E|^)((?>[^\Q" & $sSepChr & $sSpecialChr & "\E]*(?:" & $sSpecialChr & "[^\Q" & $sSpecialChr & "\E]*" & $sSpecialChr & ")?)+)", 3) EndFunc ;==>_StringSplitSV #Region ; ===( GPT solution )=== Func _Add_ScriptLineNumber($sScript, $sFuncName = "ConsoleWriteDebug", $iAddAtParameterNumber = 2) Local $aScript = StringSplit($sScript, @CRLF, 1), $sProcessedScript = "" ; Define the regex to match ConsoleWriteDebug with its parameters Local $sRegex = '(?i)\b' & $sFuncName & '\((.*)\)' For $i = 1 To $aScript[0] Local $sLine = $aScript[$i] ; Skip if the line does not contain the function If Not StringInStr($sLine, $sFuncName & '(') Then $sProcessedScript &= $sLine & @CRLF ContinueLoop EndIf ; Extract the parameters using RegExp Local $aMatch = StringRegExp($sLine, $sRegex, 1) If @error Or UBound($aMatch) = 0 Then $sProcessedScript &= $sLine & @CRLF ContinueLoop EndIf ; Parse the parameters Local $aParams = StringSplit($aMatch[0], ',', 1) If $aParams[0] < $iAddAtParameterNumber Then ; Add @ScriptLineNumber if not enough parameters $sLine = StringReplace($sLine, ")", ", @ScriptLineNumber)") ElseIf Not StringInStr($aParams[$iAddAtParameterNumber], "@ScriptLineNumber") Then ; Insert @ScriptLineNumber if missing in the target parameter $aParams[$iAddAtParameterNumber] = "@ScriptLineNumber" $sLine = $sFuncName & "(" & _JoinParams($aParams) & ")" EndIf $sProcessedScript &= $sLine & @CRLF Next Return $sProcessedScript EndFunc ;==>_Add_ScriptLineNumber ; Helper function to join parameters Func _JoinParams($aParams) Local $sJoined = "" For $i = 1 To $aParams[0] $sJoined &= ($i > 1 ? ", " : "") & $aParams[$i] Next Return $sJoined EndFunc ;==>_JoinParams #EndRegion ; ===( GPT solution )===1 point -
How can I detect the freeze of a script from within?
argumentum reacted to CYCho for a topic
I just finished 1000 loops of run and close of the program including the RichEdit and I coudn't see even 1% change of memory usage. If it happens I will just kill the process in the task manager and don't worry about it.1 point -
How can I detect the freeze of a script from within?
CYCho reacted to argumentum for a topic
Heed my words coder: do testing. Don't trust anyone other than your own testing. 😇1 point -
But the first and main issue here is HOW will you programmatically know that the script is frozen ?1 point
-
How can I detect the freeze of a script from within?
CYCho reacted to argumentum for a topic
use #include <Timers.au3> _Timer_SetTimer ( $hWnd [, $iElapse = 250 [, $sTimerFunc = "" [, $iTimerID = -1]]] ) or if that does not do it, do some IPC from a watcher script that will handle the frozen one, because if is frozen, how are you gonna unfreeze it ?1 point -
Maybe... _WinAPI_IsHungAppWindow() https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_IsHungAppWindow.htm /edit i may have been in a bit of a hurry there, guess i misunderstood you, i should have read the whole post and not just the topic. 😛1 point
-
Run as TrustedInstaller using DLL (NSudoDM.dll, NSudoAPI.dll)
Tony4219 reacted to argumentum for a topic
$iProcID = CreateProcessAsTI('', 'cmd.exe /k color 06 & title TrustedInstaller mode & whoami /groups /fo list |find "Group Name:"') that way, I can see and be shown1 point -
@malcev is right, you don't need any external dll to run a process with the same priviledges as TrustedInstaller. To achieve this you can use the undocumented NtImpersonateThread() function (more info here) or simply documented WinAPIs. #RequireAdmin #include-once #include <SecurityConstants.au3> #include <StructureConstants.au3> #include <ProcessConstants.au3> #include <WinAPIProc.au3> $iProcID = CreateProcessAsTI('cmd.exe', '/t:06') Func CreateProcessAsTI($sAppName, $sCmdLine = '') Local $iPID = StartTIService() If @error Then Return SetError(1, @error, False) EnablePrivilege($SE_DEBUG_NAME) EnablePrivilege($SE_IMPERSONATE_NAME) ImpersonateSystem() Local $hTIProcess = _WinAPI_OpenProcess(BitOR($PROCESS_DUP_HANDLE, $PROCESS_QUERY_INFORMATION), False, $iPID) If @error Then SetError(2, 0, False) Local $hTIToken = _WinAPI_OpenProcessToken(0x2000000, $hTIProcess) If Not $hTIToken Then _WinAPI_CloseHandle($hTIProcess) Return SetError(3, 0, False) EndIf Local $tSECURITY_ATTRIBUTES = DllStructCreate($tagSECURITY_ATTRIBUTES) $tSECURITY_ATTRIBUTES.nLength = DllStructGetSize($tSECURITY_ATTRIBUTES) $tSECURITY_ATTRIBUTES.lpSecurityDescriptor = Null $tSECURITY_ATTRIBUTES.bInheritHandle = False Local $hDupToken = _WinAPI_DuplicateTokenEx($hTIToken, 0x2000000, $SECURITYIMPERSONATION, $TOKENIMPERSONATION, $tSECURITY_ATTRIBUTES) If $hDupToken = 0 Then _WinAPI_CloseHandle($hTIToken) Return SetError(4, 0, False) EndIf Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO) $tSTARTUPINFO.lpDesktop = 'Winsta0\\Default' Local $tPROCESS_INFORMATION = DllStructCreate($tagPROCESS_INFORMATION) If Not _WinAPI_CreateProcessWithToken($sAppName, $sCmdLine, $CREATE_UNICODE_ENVIRONMENT, $tSTARTUPINFO, $tPROCESS_INFORMATION, $hDupToken, $LOGON_WITH_PROFILE) Then _WinAPI_CloseHandle($hDupToken) _WinAPI_CloseHandle($hTIToken) Return SetError(5, 0, False) EndIf Return $tPROCESS_INFORMATION.ProcessID EndFunc Func StartTIService() Local $aCall $aCall = DllCall('Advapi32.dll', 'handle', 'OpenSCManagerW', 'wstr', Null, 'wstr', Null, 'dword', 0x20000000) If $aCall[0] = Null Then Return SetError(1, 0, 0) Local $hSCManager = $aCall[0] $aCall = DllCall('Advapi32.dll', 'handle', 'OpenServiceW', 'handle', $hSCManager, 'wstr', 'TrustedInstaller', 'dword', BitOR(0x80000000, 0x20000000)) If $aCall[0] = Null Then Return SetError(2, 0, 0) Local $hService = $aCall[0] Local $iBufferBytes Local Static $tagSERVICE_STATUS_PROCESS = 'dword dwServiceType;dword dwCurrentState;dword dwControlsAccepted;dword dwWin32ExitCode;' & _ 'dword dwServiceSpecificExitCode;dword dwCheckPoint;dword dwWaitHint;dword dwProcessId;dword dwServiceFlags;' Local $tStatusBuffer = DllStructCreate($tagSERVICE_STATUS_PROCESS) While True $aCall = DllCall('Advapi32.dll', 'bool', 'QueryServiceStatusEx', _ 'handle', $hService, _ 'int', 0, _ ; SC_STATUS_PROCESS_INFO 'ptr', DllStructGetPtr($tStatusBuffer), _ 'dword', DllStructGetSize($tStatusBuffer), _ 'dword*', $iBufferBytes) If Not $aCall[0] Then ExitLoop Switch $tStatusBuffer.dwCurrentState Case 0x00000001 ; SERVICE_STOPPED $aCall = DllCall('Advapi32.dll', 'bool', 'StartServiceW', 'handle', $hService, 'dword', 0, 'wstr', Null) If Not $aCall[0] Then DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hService) DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hSCManager) Return SetError(3, 0, 0) EndIf Case 0x00000002, 0x00000003 ; SERVICE_START_PENDING, SERVICE_STOP_PENDING Sleep($tStatusBuffer.dwWaitHint) ContinueLoop Case 0x00000004 ; SERVICE_RUNNING DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hService) DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hSCManager) Return SetError(0, 0, $tStatusBuffer.dwProcessId) EndSwitch WEnd DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hService) DllCall('Advapi32.dll', 'bool', 'CloseServiceHandle', 'handle', $hSCManager) Return SetError(4, 0, 0) EndFunc Func EnablePrivilege($sPrivilegeName) Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_QUERY, $TOKEN_ADJUST_PRIVILEGES)) If Not $hToken Then Return SetError(1, 0, False) Local $vLUID = _Security__LookupPrivilegeValue('', $sPrivilegeName) If Not $vLUID Then _WinAPI_CloseHandle($hToken) Return SetError(2, 0, False) EndIf Local $tTOKEN_PRIVILEGES = DllStructCreate('dword PrivilegeCount;align 4;int64 LUID;dword Attributes') $tTOKEN_PRIVILEGES.PrivilegeCount = 1 $tTOKEN_PRIVILEGES.LUID = $vLUID $tTOKEN_PRIVILEGES.Attributes = $SE_PRIVILEGE_ENABLED If Not _Security__AdjustTokenPrivileges($hToken, False, DllStructGetPtr($tTOKEN_PRIVILEGES), DllStructGetSize($tTOKEN_PRIVILEGES), Null, Null) Then _WinAPI_CloseHandle($hToken) Return SetError(3, 0, False) EndIf _WinAPI_CloseHandle($hToken) Return SetError(0, 0, True) EndFunc Func GetProcessIDByName($sProcessName) Local $aSnapshot = DllCall('kernel32.dll', 'handle', 'CreateToolhelp32Snapshot', 'dword', 0x00000002, 'dword', 0) If $aSnapshot[0] = -1 Then Return SetError(1, 0, 0) Local $hSnapshot = $aSnapshot[0] Local $iPID = -1 Local $tPROCESSENTRY32 = DllStructCreate($tagPROCESSENTRY32) $tPROCESSENTRY32.Size = DllStructGetSize($tPROCESSENTRY32) If Not DllCall('kernel32.dll', 'bool', 'Process32FirstW', 'handle', $hSnapshot, 'ptr', DllStructGetPtr($tPROCESSENTRY32))[0] Then _WinAPI_CloseHandle($hSnapshot) Return SetError(2, 0, 0) EndIf While DllCall('kernel32.dll', 'bool', 'Process32NextW', 'handle', $hSnapshot, 'ptr', DllStructGetPtr($tPROCESSENTRY32))[0] If $tPROCESSENTRY32.ExeFile = $sProcessName Then $iPID = $tPROCESSENTRY32.ProcessID ExitLoop EndIf WEnd If $iPID = -1 Then _WinAPI_CloseHandle($hSnapshot) Return SetError(3, 0, 0) EndIf _WinAPI_CloseHandle($hSnapshot) Return $iPID EndFunc Func ImpersonateSystem() Local $iPID = GetProcessIDByName('winlogon.exe') If @error Then SetError(1, @error, False) Local $hSystemProcess = _WinAPI_OpenProcess(BitOR($PROCESS_DUP_HANDLE, $PROCESS_QUERY_INFORMATION), False, $iPID) If @error Then SetError(2, @error, False) Local $hSystemToken = _WinAPI_OpenProcessToken(0x2000000, $hSystemProcess) If $hSystemToken = 0 Then _WinAPI_CloseHandle($hSystemProcess) Return SetError(3, 0, False) EndIf Local $tSECURITY_ATTRIBUTES = DllStructCreate($tagSECURITY_ATTRIBUTES) $tSECURITY_ATTRIBUTES.nLength = DllStructGetSize($tSECURITY_ATTRIBUTES) $tSECURITY_ATTRIBUTES.lpSecurityDescriptor = Null $tSECURITY_ATTRIBUTES.bInheritHandle = False Local $hDupToken = _WinAPI_DuplicateTokenEx($hSystemToken, 0x2000000, $SECURITYIMPERSONATION, $TOKENIMPERSONATION, $tSECURITY_ATTRIBUTES) If $hDupToken = 0 Then _WinAPI_CloseHandle($hSystemToken) Return SetError(4, 0, False) EndIf If Not DllCall('Advapi32.dll', 'bool', 'ImpersonateLoggedOnUser', 'handle', $hDupToken)[0] Then _WinAPI_CloseHandle($hDupToken) _WinAPI_CloseHandle($hSystemToken) Return SetError(5, 0, False) EndIf _WinAPI_CloseHandle($hDupToken) _WinAPI_CloseHandle($hSystemToken) Return SetError(0, 0, True) EndFunc PS: code based on this github repo1 point