Skip to content

Instantly share code, notes, and snippets.

@Riztazz
Created September 13, 2024 06:09
Show Gist options
  • Save Riztazz/8577e23a520416082042b3d3ef98fad9 to your computer and use it in GitHub Desktop.
Save Riztazz/8577e23a520416082042b3d3ef98fad9 to your computer and use it in GitHub Desktop.
Batch script for Windows to toggle FrameServer registry key
@echo off
REM This command turns off the display of commands being executed, for cleaner output.
REM Set the registry key path and value name, this is the path of the key and the key name that we're going to modify
set FRAME_SERVER_KEY=HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Media Foundation\Platform
set FRAME_SERVER_VAL=EnableFrameServerMode
REM Check if the registry key and value exist
reg query "%FRAME_SERVER_KEY%" /v %FRAME_SERVER_VAL% 2>nul || (
REM If the key or value does not exist, create it and set it to 0
echo EnableFrameServerMode key not found. Creating it and setting to 0.
reg add "%FRAME_SERVER_KEY%" /v %FRAME_SERVER_VAL% /t REG_DWORD /d 0 /f
REM Exit the script after creating the key
exit /b 0
)
REM Retrieve the current value of EnableFrameServerMode and assign it to FRAME_SERVER_MODE
set FRAME_SERVER_MODE=
for /f "tokens=3" %%a in ('reg query "%FRAME_SERVER_KEY%" /v %FRAME_SERVER_VAL% ^| findstr %FRAME_SERVER_VAL%') do (
REM Extract the value (in hexadecimal format) from the registry query result
set FRAME_SERVER_MODE=%%a
)
REM Check if the value was successfully retrieved
if not defined FRAME_SERVER_MODE (
REM If no value was retrieved, show an error message and exit
echo Failed to retrieve the EnableFrameServerMode value!
exit /b 1
)
REM If the value of FRAME_SERVER_MODE is in hexadecimal format (starts with 0x), convert it to decimal
if "%FRAME_SERVER_MODE:~0,2%"=="0x" (
set /a FRAME_SERVER_MODE=%FRAME_SERVER_MODE%
)
REM Toggle the value: if it is 0, change it to 1; if it is 1, change it to 0
if %FRAME_SERVER_MODE%==0 (
echo EnableFrameServerMode is 0. Changing it to 1...
reg add "%FRAME_SERVER_KEY%" /v %FRAME_SERVER_VAL% /t REG_DWORD /d 1 /f
) else (
echo EnableFrameServerMode is 1. Changing it to 0...
reg add "%FRAME_SERVER_KEY%" /v %FRAME_SERVER_VAL% /t REG_DWORD /d 0 /f
)
REM Inform the user that the operation is complete
echo Done. Please restart the application using the camera.
REM Pause the script for user to see the output
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment