Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- chcp 1252
- :Variables -- Initialize Environment Variables -- v1.0.1
- SETLOCAL
- SET "#Process=vlc.exe" rem -- change this to what you want the process to be
- 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
- :InitialCheck -- Search for the window title on the selected process to find the one PID to track from then on
- ECHO Searching for the correct process (%#Process%) via windows title (%#WinTitle%)
- CALL :GetProcessInfo #WhichPID
- IF NOT DEFINED #WhichPID (
- ECHO ERROR: Could not find valid/correct "%#Process%" process to track...
- TASKLIST.EXE /FI "IMAGENAME EQ %#Process%" /V
- GOTO :ExitBatch
- ) ELSE (
- ECHO Tracking PID: %#WhichPID% for changes...
- CALL :GetWindowTitle #InitialTitle
- )
- :Wait4Change -- Wait for changes to the selected PID (with 5 second delay)
- TIMEOUT 5 /NOBREAK >NUL
- CALL :GetWindowTitle #CurrentTitle
- IF /I "%#CurrentTitle%"=="%#InitialTitle%" GOTO :Wait4Change
- :RunCURL -- with extra info to show the window changes
- ECHO:
- ECHO Title changed from "%#InitialTitle%" to "%#CurrentTitle%"
- IF %#Process% == vlc.exe (set "#postman=%#CurrentTitle:~0,-19%") else (set #postman=%#CurrentTitle%)
- ECHO Sending %#postman%
- curl -X POST -F "myText=%#postman%" http://192.168.2.20/postFormSimple
- SET "#InitialTitle=%#CurrentTitle%"
- GOTO :Wait4Change
- :ExitBatch -- exit the script and clean out the environment variables
- ENDLOCAL
- EXIT /B
- :GetProcessInfo -- subroutine (%1 = variable name)
- 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
- IF NOT DEFINED #TaskList GOTO :EOF
- FOR /F %%p IN ('ECHO %#TaskList:~25%') DO SET "%~1=%%~p" -- Get the actual PID here
- EXIT /B
- :GetWindowTitle -- subroutine (%1 = variable name)
- IF "%~1"=="" GOTO :EOF
- 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
- EXIT /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement