Questions tagged [batch-file]
A batch file is a text file containing a series of commands that are executed by the command interpreter on MS-DOS, IBM OS/2, or Microsoft Windows systems.
3,083
questions
0
votes
0
answers
16
views
How to Fix Error If Variable Contains Double Quotes
Batch Script:
@echo Off
:: Works
::set "var=C:\Program Files\7-Zip\7z.exe"
::set "var=cmd "C:\Program Files\7-Zip\7z.exe""
::set "var=CMD "C:\Program Files\7-...
0
votes
1
answer
38
views
Why does an `echo` with brackets `()` break the `if` statement?
The if statement in following code shouldn't trigger, but it does. If I change echo () to echo [], it works as intended. So apparently it has something to do with the brackets ().
set a=1
set b=2
...
0
votes
1
answer
25
views
How to extract a part of a line that is between two specific strings using a batch script [closed]
I am trying to extract strings which are between <meta property="al:ios:url" content="snssdk1180://live?room_id= and " data-rh="true">.
Example Input:
<meta ...
0
votes
0
answers
16
views
MultiMonitorTool - Batch files [closed]
I'm looking for help in creating a batch file that can activate the disable/enable switch on my 3rd monitor using the Multimonitor Tool. I want to link these functions to my stream deck so I can ...
0
votes
0
answers
31
views
CPU affinity toggle .BAT file [closed]
I have a 4 core CPU (i7-7600K Win 10) and I use a program that requires the following 'ritual' to run properly...
Go to Task Manager/Details/program's affinity settings.
Disable Core 0
Hit OK
Re-...
3
votes
2
answers
360
views
Windows Batch Script: how to recursively go through all files except certain file types and folders?
I'm trying to do a replace string operation on all files except those in .git folder and all pycache directories which can appear nested in any nested directory. I'm executing the script in the root ...
1
vote
0
answers
42
views
Get Only The Value of `WMIC PageFile Get AllocatedBaseSize` CMD
CMD Command wmic PageFile Get AllocatedBaseSize | findstr "[0-9]" 2>Nul, Output is:
512.
I use For /F Loop to get the value.
for /f %a in ('wmic PageFile Get AllocatedBaseSize ^| findstr &...
1
vote
1
answer
107
views
How a Batch Script recognize the source that executed it?
How does the batch script known the source that executed it?
Executed / called from Command line CMD
Executed from Batch file (either from the file itself or another batch file)
Illustration:
@Echo ...
0
votes
1
answer
60
views
Copy and rename batch file
1folder (cover.jpg)
2folder (cover.jpg)
3folder (cover.jpg)
.
.
There are so many jpg file with same name cover.jpg in multiple folders.
I am trying to copy and rename all cover.jpg in another folder ...
-2
votes
1
answer
81
views
Faster Way To Getting Administrator Privileges Within Windows Terminal
As far as I know, the easiest way to get administrator privileges from batch Script is by calling PowerShell.
@echo off
fltmc.exe >nul || (PowerShell.exe start -verb runas wt.exe '%~0'& exit /b)...
0
votes
0
answers
29
views
Create Task Scheduler with No Triggers Set
I need to Create a Task Scheduler with parameters:
No Triggers
Available both in AC and DC
I learn SCHTASKS /? help, but haven't found what I mean.
I tried:
SCHTASKS /Create /TN "Test" /TR ...
0
votes
1
answer
134
views
Back from Elevated Admin to Not Elevated
When running Batch Script with Administrator privileges, how to back to not Admin?
I tried this example:
@echo off
:Demo
CLS
fltmc >nul && (echo Admin& set $A=y) || (echo Not Admin&...
1
vote
1
answer
48
views
Remove Empty Line at Top Command Prompt Start Up Display
This question is a continuation of post Modify Windows CommandLine Start Up Text
After I succeeded in modifying the cmd startup display from its origin, so that it looked like this:
CMD:
Still there ...
0
votes
1
answer
68
views
Modify Windows CommandLine StartUp Text
I want to replace both text Powershell Startup and CMD StartUp below
# PowerShell
PS C:\Users\Admin>
# CMD
C:\Users\Admin>
with
PS >
CMD >
Like Python Start Up that only showing
>>...
0
votes
2
answers
54
views
Getting Two Character Variable Without Pressing Enter (PowerShell/ CMD)
Bash Script
#! /bin/bash
read -n 2 -p '2 digit:' ans;
echo $ans
When i finish input two character, the script continue, without waiting me to press enter
And what I have pressed saves to the variable ...
-1
votes
1
answer
137
views
Get String Length - How It Works
I not asking about a problem, only about how it works.
@echo off
Set str=You
Call :$len str len
set len
Set str=I You
Call :$len str len
set len
Set str=I and You
Call :$len str len
set len
Set ...
3
votes
2
answers
308
views
What Equivalent %* of Batch in PowerShell
Batch Script:
@echo off
if not "!!"=="" setlocal enabledelayedexpansion
for /f "tokens=4*" %%a in (
'dir /AD "%USERPROFILE%\" ^| find "DIR" ^| Find /...
0
votes
0
answers
73
views
Change Regional Format
What is command to change regional format to other region with Batch script?
If in powershell, i do this with:
$GID=111
Set-WinHomeLocation $GID
0
votes
1
answer
33
views
Get TimeZone Display Name Batch Script
Batch code:
@echo off
for /f "tokens=1*" %%a in ('TZUTIL /g') do set TZID=%%a %%b
SetLocal EnableDelayedExpansion
for /f "tokens=1-4" %%a in ('TZUTIL /L') do (
set $U=%%a& ...
0
votes
0
answers
26
views
scheduled batch file stops running and reports error
I have a batch file that contains the following line:
@robocopy E:\ G:\ /DCOPY:DAT /xd $* syste* /xf ~* /s /xo /np /copyall /log:c:\back-EG.txt
It is scheduled to run on the first day of month. I ...
0
votes
2
answers
51
views
Convert Output Date to Another Format
Batch code:
echo %date%
Output:
03/04/2024
I need to convert the output to:
April 03,2024
In Powershell i can do this with:
date -f 'MMMM dd,yyyy'
What code i need to do this in pure Batch ?
Not ...
0
votes
0
answers
62
views
Can you write a script that contains both bash (or sh) and powershell (or cmd, bat) so the same file can be executed on Win and *nix?
I have a script that needs to run on Windows, Linux and MacOS.
I know Windows determines how to run a script by using the file extension, where *nix will use the #!.
I'm hoping there is enough syntax ...
3
votes
3
answers
490
views
Set Variable in one line Batch
set var1=Demo
set var2=%var1%
echo %var2%
rem Output:Demo
Why does set var2 below not work if in one line with set var1?
set var1=& set var2=
set var1=Demo& set var2=%var1%
echo %var2%
rem ...
0
votes
0
answers
21
views
If I created a task on a user called "A" and I want it to be executed on user "B", how do I do it?
I'm looking for help with "Task Scheduler" Windows 10
I don't know how to do it but basically, I have two users, "A" has admin rights and "B" does not.
I also saved the ....
1
vote
1
answer
46
views
Get some spaces in a Batch
In PowerShell:
$val = ' '
$val *=5
write-host "[$val]"
# Output is 5 spaces:> [ ]
But in Batch:
set "val= "
set /a val*=5
echo [%val%]
rem Output is zero:> [0]
How i ...
0
votes
0
answers
26
views
Send input to running program Batch
I would like to start a cmd line program in Batch and be able to communicate with it.
Currently I am starting the program with start /b cmd /c "cli_program.exe" > log.txt. I am currently ...
2
votes
1
answer
38
views
Get Highest Value from String Batch File
Batch code:
set list=4 8 1
for %%a in (%list%) do set highest=???
how can I get and save the highest value into a variable?
0
votes
0
answers
47
views
How to align spaces in CMD code output
My Batch code:
@echo off
set phones="iPhone 12" "Galaxy S5 4G" "Nokia 7"
set manufs=US "South Korea" Finland
SetLocal EnableDelayedExpansion
set n=& for %%a ...
1
vote
1
answer
34
views
How do I show parts of a string?
@echo off
set keys=_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
SetLocal EnableDelayedExpansion
from keys above, command echo !keys:~1,1! output A, command echo !keys:~4,1! output D.
my question:
How do I ...
0
votes
0
answers
26
views
Trying to find .exe over multi drive wide search in a bat file. Tried with relative path commands
As stated in the title I have a bat file set up to locate and run 2 separate exe's. One is located in the same folder as the bat file which for this %~dp0 works just fine. The second exe is one to a ...
0
votes
0
answers
20
views
date time stamps turned from legible to gibberish in log file -batch file
I have a batch file which is at the end of this post. One second after I launched the batch file, I opened the log file and found that it contained the following two lines:
Fri 03/22/2024
02:19 PM
...
0
votes
2
answers
33
views
How can I echo the actual logged in user if running batch as administrator?
I would like to know which user is logged in to Windows from the bat script I launch with right click and "Run as Administrator". If I try echo %username% the script obviously output "...
0
votes
0
answers
16
views
Removing User Account through Registry using .BAT [duplicate]
I am not the best at scripting but do know enough to write and modify to do what I want.
This is an Enterprise environment and after adding a computer to the domain, we would like to delete the user ...
1
vote
0
answers
41
views
ilovepdf desktop leaves warning message
ilovepdf desktop program shows the message "Your PDFs have been converted successfully" when the conversion process is completed while right-clicking on Windows. The question is, how to ...
1
vote
1
answer
57
views
Any way to do a Batch file move operation only when the HDD is idle-ish?
I know how to check if a specific program is running like winrar which might indicate usage on drive d: but is there a better way to determine if a drive is relatively idle enough (via Batch or other ...
0
votes
1
answer
64
views
batch findstr not working with string saved in a variable
I'm trying to find a string inside a file.txt using findstr and I have the following issue:
set "log_file=C:\Tools_Dev\log_file.txt"
a-findstr C/:"text to find" %log_file%
works ...
1
vote
1
answer
77
views
Batch file to output MD5 hash to a text file starting at a specific directory
@echo off
set "src_dir=C:\Users\\Documents\projects\Config\ABC"
set OUTFILE="C:\Users\Documents\Scriptoutput.txt"
echo %OUTFILE%
pushd %cd%
cd %src_dir%
for /r %%f in (*) do (
...
1
vote
0
answers
47
views
Bat file move files
I need to create a bat file to move files from folder 1 to folder 2. however, I need to keep in folder 1 the files created in the lasts 3 hours. all the rest old files must be move to folder 2. I´ve ...
0
votes
1
answer
89
views
Windows Terminal: Open cmd.exe then run script
I want to create .bat file to open cmd.exe in Windows Terminal and activate python environment
cd D:\pythonApp
venv\Scripts\activate
this successfully open cmd in Terminal and set the directory
wt....
0
votes
1
answer
47
views
Automatically closing ('OK'-ing) a Windows Script Host dialogue box from a batch script
I have an incredibly annoying problem where my Win 10 license keeps randomly deactivating for no reason. Sometimes it lasts weeks without doing it but recently it seems to be doing it every other day. ...
0
votes
0
answers
17
views
Read git label in version format on Windows
I have the following bash script which read the last label from git which is in version format (1.2.3.4).
git tag --sort=-refname | awk 'match($0, /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)' | head -n 1
I ...
-1
votes
1
answer
73
views
Start .bat file via php
I'm using
system('START C:\[address]\refresh.bat');
but when I start this I get:
C:\[address]>git fetch
'git' is not recognized as an internal or external command,
operable program or batch file.
...
0
votes
0
answers
62
views
Why is my scheduled task only starting when I open the Task Scheduler?
I created a scheduled task in the Windows Task Scheduler (W10). It triggers on startup (or log in of any user, I am flexible there) and launches a .bat file.
The task runs with the privileges of user ...
0
votes
1
answer
145
views
(SOLVED) how to enable and disable device in one batch file [duplicate]
I want a shortcut that enable/disable a network card according to its status. I figured out how to enable or disable using either devcon, wmic and pnputil or found some Q&As here that suggest ...
1
vote
2
answers
133
views
Copy single file in to sub folders of destination root folder
I need to copy a single text file inside a (source) folder in to all (480) sub folders of another parent folder.
To keep it simple (I will amend the correct paths later) as I try to work out how to do ...
0
votes
2
answers
279
views
Xcopy: Copy last modified file from folder
I need to copy the last modified file of a particular extension from a folder. For example a folder contains:
File1.cas
File1.txt
File2.cas
File2.txt
File3.cas
File3.pptx
...
File100.cas
File100.pptx
...
0
votes
1
answer
45
views
Bat file display
I have a bat file i have that shows me all networks i have previously joined and inputed passwords to. however my own home network the bat file does not display the last symbol of my password, which ...
-2
votes
1
answer
59
views
Improve bat script
I'm try to improving this and make it looks better. I have two issues
When I run as administrator the file that I need won't copy in the user profile (I just run as admin to run the .bat script.
...
0
votes
0
answers
96
views
Display switch with a timeout in a Batch script
I have my PC connected to my monitor and TV. I want to be able to switch my display to the TV and launch an application through a script.
As I do this, I would like to set the audio to be the TV ...
0
votes
0
answers
86
views
Converted BAT to EXE Now Path to Temp Not Local
After converting Test.bat to Test.exe the Test.exe not finding local input file 360_2016.mp4 and the EXE file CMD Prompt displaying its path is to TEMP not local directory/folder. The EXE file is not ...