r/BatchScripts • • May 18 '24

Is there a ^ equivalents in CMD?

2 Upvotes

In a long batch script line, I would add a ^ character in numerous places to break up the line in to multiple lines for easier reading. It would execute as if it was on one line.

When I rename the .bat to .cmd it fails to run since ^ is treated differently.

Is there a way to break up a line of code in .cmd files?


r/BatchScripts • • Oct 16 '24

New to batch scripts

1 Upvotes

Afternoon guys/gals can someone assist in trying to autmate moving folders from one destination to another. The only variable would be if folders not there make it. If it is there add to it. I’m at a loss I’ve set the source and destination folders used robocopy command but can’t get the jist of it 🫣


r/BatchScripts • • Sep 16 '24

Timestamp suddenly not showing in output name?

1 Upvotes

I have this batch scripts that has been running fine and creating output with date and timestamp for each run. Today, I ran it and it is not including the timestamp.

When I double clicked the bat, there was a cmd pop up I had to respond to about security and policy and I selected A to change all (something like that). Did this response cause this?


r/BatchScripts • • May 01 '20

Need help on delete file in C: Drive. ExamplePC123.exe. Need example scripts to delete exe.

1 Upvotes

I wanted to create a batch file. Cmd: psexec \exmaplepc123 cmd Delete from cmd. Any advice? Thanks


r/BatchScripts • • Apr 15 '20

Looking for someone to make a program. Simple?

1 Upvotes

Hey Everyone, I was curious if there was a way to make a program where there is 2 inputs.

  1. Input for starting number

  2. Input for delay
    Basically there is a discord I'm in that has a count channel. This channel is where people type in the next sequential number. There is a small cooldown which is what the delay would be for. I just want to get the count super high. Maybe it wouldn't even need to count sequentially, because the server description says what the next number is and updates every 7 seconds or so. So maybe is there a way to detect what the next number is from the program detecting the number in a certain section of my screen? After detecting it, it waits a few seconds and then types said number and sends it?
    Please let me know if any of you have any ideas, thanks!


r/BatchScripts • • Apr 18 '20

Set focus on specific Chrome instance

1 Upvotes

I want to make a script to use on one of my shortcut keys on my keyboard, and I want it to set focus on the Chrome instance that is playing a video on youtube.

I have tried (new ActiveXObject("WScript.Shell")).AppActivate("Chrome");, but afaik I cannot specify which Chrome instance to focus.

Does anyone know if this is possible?


r/BatchScripts • • Sep 18 '20

A batch script that grabs certain files sizes and moves into vidcoder

1 Upvotes

I'm looking for some help with batch script. What I would like to do is have a batch script scan my hard drive video files and only grab video files over a certain size and move them to my vidcoder to be compressed. Is that something that can be done?. Any help would be greatly appreciated 🙏.


r/BatchScripts • • Aug 26 '20

Set Exit code 259 as success

1 Upvotes

I'm pretty new to Batch scripting. Please help me with the below syntax.

My aims is to set exit code 0 as success when exit code is 259.

if "%ERRORLEVEL%"=="259"{

SET intRC= 0

EXIT %intRC%

Echo "Success"}

else{

EXIT %ERRORLEVEL%

}


r/BatchScripts • • Aug 30 '20

Adobe Flash Bulk silent removal

2 Upvotes

Hi With Flash going away, I’m looking for a script that will silently find any version of Flash and uninstall it silently. This will be run over several different networks thru the Datto RMM Thanks in advance


r/BatchScripts • • Jun 15 '22

Script to move files to a specific folder and replace the old files with the new ones.

1 Upvotes

As the title explains I want a script to move multiple certain files and move them all into specific folders I am not sure if this is possible but that is why I am here so thanks for all the help and goodbye.


r/BatchScripts • • Jul 16 '14

[Request]Batch Script to Rename a JPG Based on Folder Name, and Then Copy to a New Folder.

2 Upvotes

At work we have an entire drive full of PowerPoint templates. I want to create an image gallery to basically serve as a directory, and I am hoping that a batch script will help. I have Googled, and found similar ideas, but nothing quite what I am looking for, and nothing I have been able to make work.

Here are the deets: I have a large folder called Templates. There are dozens, if not hundreds, of subfolders named ppt12543, or similar. Inside each subfolder is a file called master.jpg, among other files.

I want to rename master.jpg to the name of the subfolder it is in (eg: ppt12543.jpg), and move it to a new folder in the Templates folder called Directory. The renaming can happen at any point in the process, it doesn't necessarily need to be first, but it just needs to be the name of the folder it was moved from.

I am working with 2 versions of the folder, one to preserve as is, and the other to delete everything but the images once I have taken them, and also in case anything goes wrong. I am working with Windows 7.

If anyone has any ideas I would be extremely grateful. Thanks in advance for your help.


r/BatchScripts • • Apr 28 '15

[Request] Script to click a button on a webpage periodically

2 Upvotes

I need a sort of script or something to trigger an event (check now) on a specific URL (ifttt) periodically. I have little to no knowledge in programming but I have tried refresh clients to load the url of the button, and running the url from cmd line. The event is only ever triggered when it is clicked, and the web page will update.

Any thoughts?


r/BatchScripts • • Oct 12 '17

How do you use a loop command through the MOS window rather than notepad?

1 Upvotes

How would I type a code like this:

@echo off :start echo hi goto start

But directly to the command line rather than to notepad


r/BatchScripts • • Oct 31 '13

[Help BATCH] Checking who is logged to computer and returning their email address

2 Upvotes

I often need to check who is logged into certain machine and to get their email address for our ticketing system.

I use

set Host=%1
if "%HOST%"=="" (
set /P HOST=Enter host: %=%
)
powershell -command "WMIC /Node:%HOST% ComputerSystem Get UserName"
if "%1"=="" (
pause
)

to get the user logged to computer and this returns the user name in format "domain\prewin"

I know that I can convert prewin to email address with following:

dsquery user -samid prewin |dsget user -email

but this won't accept the output of the earlier script due the format.

Would you fellow redditors have any decent ideas of how to write a script which would check who is logged to computer in domain and then output both domain\prewin and the email address for user?


r/BatchScripts • • Oct 25 '13

[REQUEST] Batch Script to find a file and then replace it with a new version

2 Upvotes

I need to find a specific file on a system and then replace it with a new version from a network location.

For arguments sake . The file i need to find is call mountcs.txt it can exists in multiple locations on a machine. I need to search the system , find all instances then replace those instances with the new file. I am not that great at scripting and hitting a few snags. I was hoping someone could help me write a script to accomplish this.

thanks in advance to anyone who can assist.


r/BatchScripts • • Dec 21 '21

Playing Some Radios Stations with a Dynamic Menu

Thumbnail self.batch
2 Upvotes

r/BatchScripts • • Dec 24 '21

Need help with for loop and a list of wildcard file names

1 Upvotes

Pretty simple task, but I’m stuck and need help. Thank you in advance.

Built a batch script that loops through the dir looking for wildcarded file names, then copy them into a separate dir. see below:

—— Set /p dir= Enter Dir:

for /f “delims=“ %%I in (MasterFileList.txt) do (xcopy “%dir%%%I” “%dir%\TargetDir%%I”) ——

MasterFileList Examples: *390.txt *4TB.txt …

The issue is the script is not recognizing the wildcard file names.


r/BatchScripts • • Nov 07 '24

Using a txt file to store a file to file variable.

1 Upvotes

I was just curious on how I would be able to use txt file contents for a server name.

I create the txt file in one batch file:

hostname > name.txt

Then I want to use it in place of a PC/server name for net use command in a different batch file like this:

net use A: \\contentsOf"name.txt"

I just don't know how to do it. Please someone tell me it's possible🙏. & If possible how?


r/BatchScripts • • Sep 22 '21

First timer need help

1 Upvotes

I plan to use a counter variable in a loop so im testing out how it works. eg, loop1 = "hello", loop2 = "bye bye" ... etc etc. So the goal is to give every variable an incrementing name depending on what is set/read during the loop, in this case, I am are using the "hello" string for example.

@echo off

set "counter=1"

echo test%counter%

set /A test%counter% = "hello"

echo %test(%counter%)%

This is my output when I run the script:
test1

counter
But my intended output should be:
test1

hello


r/BatchScripts • • Apr 30 '17

Changing audio device in windows

1 Upvotes

So I have a random request.

I'm looking to be able to quickly switch between two audio devices in Windows 10 without having to Sound Settings and change the default playback device.

Any help would be appreciated.


r/BatchScripts • • Mar 04 '15

[WIP] OS agnostic dep management. [Mac/Debian for now]

2 Upvotes

This is a script I've been working on for a little bit. The idea is that a project would provide a file in it's root called depends.sh which would include everything that project relys on. This originated from my dotfiles repository have having many deps, like vim, zsh, janus the list goes. Wanted to share and see what you guys think?

https://github.com/andrewhood125/establish


r/BatchScripts • • Nov 07 '20

Batch script to move a file from place to another

1 Upvotes

Hello

I am looking to create a batch script to move a file from one location to another. it needs to be a batch script to run on logon for a network.

the script will need to:

start

check to see if the file is new.xyx

IF it is old.xyz Replace with new.xyz

Else end

so it will need to ideal check the age of the file or the contents of the file. the file will be a .rtf file.

so it could also move a second file and if the second file already exists then it could end?

Thanks in advance


r/BatchScripts • • Oct 24 '20

Processes_Services_Tasks_Startup.bat

Thumbnail
pastebin.com
1 Upvotes

r/BatchScripts • • Sep 27 '20

Why does it not open?

Thumbnail
docs.google.com
1 Upvotes

r/BatchScripts • • Dec 18 '24

My script to PING a remotely restarted system and alert you when it's back online

4 Upvotes

The idea here was to not have a non-stop infinite PING request bogging down network traffic and have it notify you when a system is online again after a remote restart.

@echo off

REM set minimum and maximum bounds here to match DHCP range, or optionally cover it all by doing 1-254

setlocal enabledelayedexpansion
REM default values set here:
set tgt=LocalHost
set wentOffline=0
set intervalSecs=10
set maximumChecks=30
:ShowMenu
cls
set selection=
echo Remote Restart Monitor Utility v1.2.2
echo =====================================
echo/
echo Target: %tgt%
echo Interval: %intervalSecs%
echo Maximum Tries: %maximumChecks%
echo/
echo/
echo MENU
echo ====
echo About = About this bat file
echo Interval = Set interval for checking (in seconds), default is 10
echo Max = Set maximum number of iterations, default is 30
echo Start = Start monitoring
echo Target = Set monitoring target
echo X = Exit
echo/
set /p selection= Enter option:
set selection=%selection:~0,1%
echo/
if /I "%selection%"=="A" (
cls

echo About Remote Restart Monitor Utility

echo Original Release 2018-FEB-02

echo/

echo Author Gary Ritter Jr

echo [email protected]

echo/

echo Intended to alert the user when a remotely restarted system comes back online without spamming constant ping requests.

echo Will attempt a ping every interval seconds and automatically stop when the system responds to a ping after having been unavailable.

echo Start it when you're ready to restart, if the system is already responding when it starts, it will wait to see it go offline and come back again.

pause
)
if /I "%selection%"=="M" (
set /p maximumChecks= "Maximum Iterations:"
)
if /I "%selection%"=="I" (
set /p intervalSecs= "Interval delay (in seconds):"
)
if /I "%selection%"=="S" (
set /p ready= "Really Start (Y/N)?"

if /I "!ready:\~0,1!"=="Y" goto confirmedSend
)
if /I "%selection%"=="T" (
set /p tgt= "New Target:"
)
if /I "%selection%"=="X" (
goto AllDone
)
goto ShowMenu
:confirmedSend
echo/

echo/

echo %time% It has begun...

echo/

for /L %%n in (1,1,%maximumChecks%) DO (

ping -n 1 %tgt% | find "TTL=" >nul

if errorlevel 1 (

if !wentOffline!==0 (
echo Target %tgt% is offline
)

set wentOffline=1

) else (

if !wentOffline!==1 (
echo Target %tgt% is back online
exit
)

)

timeout /t %intervalSecs% >nul

)

if !wentOffline!==0 (

echo Target did not go offline. Timed out.

) else (

echo Target is still offline at %time%. Timed out.

set wentOffline=0

)

goto done
:done
echo/

pause

goto ShowMenu
:AllDone
REMecho Press any key to exit...

REM pause >nul
endlocal