argumentum Posted July 5, 2025 Posted July 5, 2025 (edited) Running "syncthing --no-browser --no-console" used to run syncthing with "no-console" but for some reason it doesn't in Win11. Therefore a hider is needed and after trying the solutions I found online and failing me, I coded one given that is very simple to do in AutoIt. Spoiler expandcollapse popup#include <SQLite.au3> #include <Array.au3> #include <WinAPIProc.au3> #include <WinAPISysWin.au3> OnAutoItExitRegister(OnAutoItExit) Func OnAutoItExit() ;~ The exit code can be retrieved with @exitCode. ;~ The mode of exit can be retrieved with @exitMethod. ConsoleWriteLog(" OnExit: ExitCode=" & @exitCode & " - ExitMethod=" & @exitMethod & @CRLF) EndFunc ;==>OnAutoItExit Global $g_ini = StringTrimRight(@ScriptFullPath, 4) & ".ini" Global $g_logFile = StringTrimRight(@ScriptFullPath, 4) & ".log" Global $g_iLogToFile = Int(IniReadOrInit($g_ini, "Settings", "LogToFile", "1 ; 0=OFF, 1=ON")) Global $g_hOnlyHide = IniReadOrInit($g_ini, "Settings", "OnlyHide", "; HELP: use /OnlyHide to OnlyHide on load in a shortcut") Global $g_iOnlyHide = StringInStr($CmdLineRaw, "/OnlyHide") Exit main() Func main() If Not FileGetSize(@ScriptDir & "\syncthing.exe") Then ConsoleWriteLog(' "syncthing.exe" is not found in the current folder !' & @CRLF) MsgBox(262144 + 16, StringTrimRight(@ScriptName, 4), '"syncthing.exe" is not found in the current folder !', 120) Exit 6 EndIf Local $iPid = 0, $hTimer = TimerInit() If Not ProcessExists("syncthing.exe") Then $iPid = ShellExecute(@ComSpec, " /c title " & @ScriptDir & "&syncthing.exe --no-browser --no-console", @ScriptDir, "open", @SW_HIDE) ConsoleWrite('- $iPid:' & $iPid & @CRLF) EndIf While HideShowTerminal($iPid) If TimerDiff($hTimer) > 10000 Then Return 5 Sleep(300) WEnd EndFunc ;==>main Func HideShowTerminal($iPid = 0, $iActivate = 1) Local $aArray = WinList() Local $iNotFound = 1, $iCount = 0, $aCollected[UBound($aArray)][7] $aCollected[0][0] = "Title" $aCollected[0][1] = "HWD" $aCollected[0][2] = "PID" $aCollected[0][3] = "ClassName" $aCollected[0][4] = "ProcessName" $aCollected[0][5] = "WinState" $aCollected[0][6] = "WIN_STATE_VISIBLE" For $n = 1 To $aArray[0][0] If Not StringInStr($aArray[$n][0], @ScriptDir) Then ContinueLoop $iCount += 1 $aCollected[$iCount][0] = $aArray[$n][0] $aCollected[$iCount][1] = $aArray[$n][1] $aCollected[$iCount][2] = WinGetProcess($aArray[$n][1]) $aCollected[$iCount][3] = _WinAPI_GetClassName($aArray[$n][1]) $aCollected[$iCount][4] = _WinAPI_GetProcessName($aCollected[$iCount][2]) $aCollected[$iCount][5] = WinGetState($aArray[$n][1]) $aCollected[$iCount][6] = BitAND($aCollected[$iCount][5], 2) ; $WIN_STATE_VISIBLE (2) = Window is visible If "WindowsTerminal.exe" = $aCollected[$iCount][4] Or "cmd.exe" = $aCollected[$iCount][4] Then $iNotFound = 0 Switch $aCollected[$iCount][6] Case 2 WinSetState($aArray[$n][1], "", @SW_HIDE) Case Else If Not $iPid And Not $g_iOnlyHide Then WinSetState($aArray[$n][1], "", @SW_SHOW) If $iActivate Then WinActivate($aArray[$n][1]) EndIf EndSwitch EndIf Next ReDim $aCollected[$iCount + 1][7] Local $sLog = _SQLite_Display2DResult($aCollected, 0, True, " | ", " |" & @CRLF) & " |" & @CRLF ConsoleWriteLog($sLog) Return $iNotFound EndFunc ;==>HideShowTerminal Func ConsoleWriteLog($sStr) Local Static $sTimeStamp = "" If $sTimeStamp = "" Then $sTimeStamp = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC If $g_iLogToFile Then FileWriteLine($g_logFile, @CRLF & $sTimeStamp & @CRLF) EndIf ConsoleWrite($sStr) If $g_iLogToFile Then FileWriteLine($g_logFile, $sStr) EndFunc ;==>ConsoleWriteLog Func IniReadOrInit($ini, $sec, $key, $def) Local $vRet = IniRead($ini, $sec, $key, @CRLF) If $vRet = @CRLF Then $vRet = $def IniWrite($ini, $sec, $key, $def) EndIf If StringInStr($vRet, ";") Then $vRet = StringStripWS(StringLeft($vRet, StringInStr($vRet, ";") - 1), 3) Return $vRet EndFunc ;==>IniReadOrInit ...not a OMG, what an excellent example but, a simple solution to a simple problem. Posted in the help area because I compiled it and posted in the files section. If anyone needs anything else from this or just don't work, post a comment. Usage: Drop it in the same folder as syncthing is in, and run from there. The /OnlyHide argument is to only hide it, because the default action is show if hidden and hide if shown. The compiled file is in the downloads area. Edited July 5, 2025 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution argumentum Posted July 5, 2025 Author Solution Posted July 5, 2025 Entry just to mark the post as solved Danyfirex 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now