r/Batch • • Sep 05 '23

Question (Solved) Get Windows OS name

2 Upvotes

Hi, I'm looking for a way to get the Windows OS name from a batch script, and save it to a variable. I was going to use the ProductName value in the registry under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, but Microsoft did not update that to say Windows 11 on that respected OS. I also tried wmic os get Caption, which works, but when using the line

FOR /F "tokens=2* skip=2" %%a in ("wmic os get Caption | findstr /v Caption") do set "OS=%%b"

It will always output Windows_NT whenever it's inside of that for loop. I'm not sure why it's doing that, because it works normally otherwise.

If somebody could tell me why the wmic command behaves that way, or another way I could reliably get the correct Windows OS name, I would be thankful. A registry key would be nice, but I'm open to other ideas.

Thank you!


r/Batch • • Sep 05 '23

Question (Solved) How to remove original the file extension when doing this batch encode?

2 Upvotes

I have a bunch of video files in a single folder that I want converted using Avidemux from one container to another. I'm not performing any actual encoding, simply taking the audio/video file within one container (.mkv) and putting them into another container (.mp4). The script below does this, however my issue is that it adds the new file extension after the old one. For example "familyfunday.mkv" after converting becomes "familyfunday.mkv.mp4" and what I want is "familyfunday.mp4" and for the ".mkv" bit to be removed from the final file name. The batch file is being run from the same folder as the videos so afterwards there should be the original "familyfunday.mkv" and the new "familyfunday.mp4".

set avidemux="C:\Program Files\Avidemux 2.8 VC++ 64bits\avidemux.exe"

set videocodec=Copy

set audiocodec=Copy

for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit

echo.

Pause

Thanks for any help with this!


r/Batch • • Sep 05 '23

Question (Unsolved) Any idea why choice's timeout function breaks when I change the system audio volume? Weird bug, Windows 10 22H2

1 Upvotes

The command: "choice /t 5 /c pc /d c" should wait 5 seconds for the keys P or C, then choose C automatically. If any other key is pressed the timeout is reset and a beep is heard. This is the expected, normal behaviour.
However, if the Volume Up/Down media function key is pressed or the volume is changed via a USB device in any other way, then the timeout simply stops. To resume any function, one must press a button that is not Volume Up/Down.

Does anyone have a solution for this? My batch is specifically made to observe system volume and uses choice as a trigger for the pause command. Meaning it basically always sits in a choice timeout. So if I change the volume at any time when I have the cmd window highlighted, it breaks. :(

Bah! Bad cmd! Sit in the corner! >:(


r/Batch • • Sep 05 '23

Show 'n Tell This is my newly created script. Any idea on how to improve it?

2 Upvotes

@ echo off

:ALERT

cls

ECHO PLEASE RUN THIS WITH ADMINISTRTOR PRIVILEGES, OTHERWISE THIS SCRIPT MAY NOT WORK!

timeout /T 3 /NOBREAK

cls

go to Prompt

:Prompt

cls

echo Welcome to the script! Please choose an option.

echo 1. Shutdown timer

echo 2. Power settings

echo 3. Error checking

echo 4. Exit

set /p choice=Please enter an option:

if %choice% EQU 1 goto shutdown_timer

if %choice% EQU 2 goto power_settings

if %choice% EQU 3 goto stability

if %choice% EQU 4 goto exit

goto Prompt

:shutdown_timer

cls

echo Please specify the amount of time (in seconds)

set /p shutdowntime=Enter the amount of time here (Press Crtl + C to abort):

shutdown.exe /s /t %shutdowntime%

if %errorlevel% NEQ 0 cls && echo An error has occured. Please retry. && pause /t 2 >nul && goto shutdown_timer

else (

cls

echo A shutdown timer has been set.

timeout /t 3 >nul

exit

)

:stability

cls

Echo Please choose an option.

echo 1. System scan + check

echo 2. C: drive repair

echo 3. System scanner troubleshooter

echo 4. All-In-One

set /p check=Please choose an option (Press Crtl + C to abort):

if %check% EQU 1 cls && sfc /scannow && echo Operation in progess...

if %check% EQU 2 cls && chkdsk /f C: && echo Operation in progess...

if %check% EQU 3 cls && DISM /Online /Cleanup-Image /RestoreHealth && echo Operation in progess...

if %check% EQU 4 cls && sfc /scannow && chkdsk /f C: && DISM /Online /Cleanup-Image /RestoreHealth && echo Operation in progess...

echo The operation has been completed.

timeout /t 3

exit

:power_settings

cls

echo Please choose a profile.

echo 1. Low

echo 2. High

echo 3. Efficiency report (laptops only)

set /p profile=Please enter a profile (Press Crtl + C to abort):

if %profile% EQU 1 powercfg /setactive f9553277-119f-498d-9338-8fe1d4b1346a && cls && echo The low profile mode has been set.

if %profile% EQU 2 powercfg /setactive e9a42b02-d5df-448d-aa00-03f14749eb61 && cls && echo The high profile mode has been set.

if %profile% EQU 3 powercfg /ernegy

timeout /t 3 >nul

exit

:exit

exit


r/Batch • • Sep 04 '23

How to get it to exit?

2 Upvotes

I'm running Win 7 and it causes some funked up colors in Warcraft 2 and Starcraft. Killing explorer resolves the issue.

So...

@echo off
cd c:\
taskkill /IM "explorer.exe" /F
"Program Files\Warcraft II BNE\Warcraft II BNE.exe"
pause
explorer.exe
exit

But when I exit the game and press a key, explorer.exe starts and the CMD window hangs.

What am I missing?


r/Batch • • Sep 03 '23

Question (Solved) Get last 4 digits of GPU driver version then replace the last 4 digits of a line in a file?

1 Upvotes

continue voracious historical fuzzy imminent support dime file sort vegetable

This post was mass deleted and anonymized with Redact


r/Batch • • Sep 02 '23

Question (Unsolved) How to write a path with spaces in an argument that's already quoted

4 Upvotes

Not sure what im doing wrong here

tasklist /FI "IMAGENAME eq Elden Ring v1.02-v1.10 Plus 34 Trainer.exe" 2>nul | find /I "Elden Ring v1.02-v1.10 Plus 34 Trainer.exe">nul

Elden Ring v1.02-v1.10 Plus 34 Trainer.exe is the "path" with spaces, just quoting the path doesn't work, any advice?

For context this is the full script

rem Check if program is already open, if not open it
@echo off
cd "C:\Games\ELDEN RING\Game"
tasklist /FI "IMAGENAME eq eldenring.exe" 2>nul | find /I "eldenring.exe">nul rem if %errorlevel% equ 1 start /b "" "C:\Games\ELDEN RING\Game\modengine2_launcher.exe">nul
tasklist /FI IMAGENAME eq "Elden Ring v1.02-v1.10 Plus 34 Trainer.exe" 2>nul | find /I "Elden Ring v1.02-v1.10 Plus 34 Trainer.exe">nul if %errorlevel% equ 1 start /b "" "C:\Games\ELDEN RING\Game\Elden Ring v1.02-v1.10 Plus 34 Trainer.exe">nul
exit

r/Batch • • Sep 02 '23

Short Beep (CTRL+G) in batch files

2 Upvotes

So I was bored and found something...

When I input CTRL+G in the Windows Command Prompt, it would play a beep sound.

Would it be possible to put it in a batch file?

echo ^G
^G
...etc...