Skip to main content

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.

Filter by
Sorted by
Tagged with
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-...
Mr.Key7's user avatar
  • 517
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 ...
Qwert Yuiop's user avatar
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 ...
Enema State's user avatar
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 ...
user1914329's user avatar
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-...
Rix's user avatar
  • 1
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 ...
Macky's Printing Services's user avatar
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 &...
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
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 ...
Silver Lee's user avatar
-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)...
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
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&...
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
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 >>...
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
-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 ...
Mr.Key7's user avatar
  • 517
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 /...
Mr.Key7's user avatar
  • 517
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
Mr.Key7's user avatar
  • 517
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& ...
Mr.Key7's user avatar
  • 517
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 ...
joehua's user avatar
  • 287
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 ...
Mr.Key7's user avatar
  • 517
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 ...
David Alsh's user avatar
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 ...
Mr.Key7's user avatar
  • 517
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 ....
Samir Mahmoud's user avatar
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 ...
Mr.Key7's user avatar
  • 517
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 ...
octalgon's user avatar
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?
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
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 ...
Mr.Key7's user avatar
  • 517
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 ...
heyimvic's user avatar
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 ...
joehua's user avatar
  • 287
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 "...
Kintaro's user avatar
  • 33
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 ...
Corey Jackson's user avatar
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 ...
Burak Celik's user avatar
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 ...
Bricktop's user avatar
  • 303
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 ...
Fernando Lisa's user avatar
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 ( ...
Sam sh's user avatar
  • 21
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 ...
Matias Squartini's user avatar
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....
uingtea's user avatar
  • 101
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. ...
tbmmbt's user avatar
  • 1
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 ...
Tomas Kubes's user avatar
-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. ...
Hopm Mpoн's user avatar
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 ...
Reygok3's user avatar
  • 11
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 ...
user2048695's user avatar
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 ...
Bel's user avatar
  • 25
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 ...
Hemil Mehul Shah's user avatar
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 ...
Simon Wilson's user avatar
-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. ...
Daniel Jiménez's user avatar
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 ...
RemotelyController's user avatar
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 ...
CANJMP's user avatar
  • 23

1
2 3 4 5
62