Advertisement
Guest User

Window Title

a guest
Mar 25th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. @ECHO OFF
  2. chcp 1252
  3.  
  4. :Variables -- Initialize Environment Variables -- v1.0.1
  5. SETLOCAL
  6. SET "#Process=vlc.exe" rem -- change this to what you want the process to be
  7. SET "#WinTitle=VLC media player" rem -- This is what I used for testing, but you should change it to be what you need for the first run
  8.  
  9. :InitialCheck -- Search for the window title on the selected process to find the one PID to track from then on
  10. ECHO Searching for the correct process (%#Process%) via windows title (%#WinTitle%)
  11. CALL :GetProcessInfo #WhichPID
  12. IF NOT DEFINED #WhichPID (
  13. ECHO ERROR: Could not find valid/correct "%#Process%" process to track...
  14. TASKLIST.EXE /FI "IMAGENAME EQ %#Process%" /V
  15. GOTO :ExitBatch
  16. ) ELSE (
  17. ECHO Tracking PID: %#WhichPID% for changes...
  18. CALL :GetWindowTitle #InitialTitle
  19. )
  20.  
  21. :Wait4Change -- Wait for changes to the selected PID (with 5 second delay)
  22. TIMEOUT 5 /NOBREAK >NUL
  23. CALL :GetWindowTitle #CurrentTitle
  24. IF /I "%#CurrentTitle%"=="%#InitialTitle%" GOTO :Wait4Change
  25.  
  26.  
  27. :RunCURL -- with extra info to show the window changes
  28. ECHO:
  29. ECHO Title changed from "%#InitialTitle%" to "%#CurrentTitle%"
  30.  
  31. IF %#Process% == vlc.exe (set "#postman=%#CurrentTitle:~0,-19%") else (set #postman=%#CurrentTitle%)
  32.  
  33. ECHO Sending %#postman%
  34. curl -X POST -F "myText=%#postman%" http://192.168.2.20/postFormSimple
  35. SET "#InitialTitle=%#CurrentTitle%"
  36. GOTO :Wait4Change
  37.  
  38. :ExitBatch -- exit the script and clean out the environment variables
  39. ENDLOCAL
  40.  
  41. EXIT /B
  42.  
  43. :GetProcessInfo -- subroutine (%1 = variable name)
  44. FOR /F "DELIMS=" %%L IN ('TASKLIST.EXE /FI "IMAGENAME EQ %#Process%" /V ^| FIND /I "%#WinTitle%"') DO SET "#TaskList=%%L" rem -- Get all the process info here
  45.  
  46. IF NOT DEFINED #TaskList GOTO :EOF
  47. FOR /F %%p IN ('ECHO %#TaskList:~25%') DO SET "%~1=%%~p" -- Get the actual PID here
  48. EXIT /B
  49.  
  50. :GetWindowTitle -- subroutine (%1 = variable name)
  51. IF "%~1"=="" GOTO :EOF
  52. FOR /F "TOKENS=1*" %%a IN ('TASKLIST.EXE /FI "PID EQ %#WhichPID%" /FO LIST /V ^| FIND "Fenstertitel"') DO SET "%~1=%%b" rem --Get Window Title of selected PID info here
  53. EXIT /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement