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,072
questions
0
votes
1
answer
25
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
41
views
Modify Windows CommandLine Start Up 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
1
answer
43
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
2
answers
107
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
242
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
46
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
28
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
25
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
46
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
53
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
442
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
43
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
25
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
36
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
44
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
31
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
25
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
votes
0
answers
14
views
Conda Environment duplication without downloading python
I did a GUI application and my companny does not allow me to use .exe . Therefore, I have sent the project to shared folder and I created a .bat file to go that path and write python main.py. Hoewever,...
1
vote
0
answers
40
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
56
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
44
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
74
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
44
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 ...
-1
votes
0
answers
53
views
Batch Script: Setting Default Terminal Application [closed]
Hello i have been trying to change the Default window terminal from terminal to Windows Console Host using batch i could not find any way online and i have zero idea how to do this the setting im ...
0
votes
1
answer
80
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
40
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
14
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
64
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
59
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
131
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
118
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
259
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
42
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
57
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
92
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
80
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 ...
0
votes
1
answer
89
views
Write batch file to remove lines starting with a set of numbers (eg. 19:) and save file to a new location
I'm trying to write a batch file to remove lines from a text file that start with 19:, 20:, 21: and 22: and then save the file to a different directory. What I've tried is:
findstr /v /b "19:&...
0
votes
1
answer
67
views
Batch file with multiple commands
I have a batch file to start several programs. it has quit working. It starts the 1st 2 and stops. No error message.
e.g.
G:\KarenPwrTool\Replicator\PTReplicator.exe
G:\FileManagers\VfileViewer\v.exe ...
0
votes
0
answers
306
views
Running a batch silently, but how can I get process ID to show a specific name?
I have followed this here to run a batch file silently, in the background and doesn't show on taskbar, it's great.
How to run a batch file without launching a "command window"?
The thing is, ...
1
vote
1
answer
68
views
Weird effects when one CMD script runs another, from inside a function
When one BAT or CMD script runs another (without call), that should not return, right?
It sometimes does!
And it searches the same function label in that other script?!?
Example: (what do you think ...
0
votes
3
answers
73
views
Batch (or some other file) to have scheduled in Task Scheduler for a popup that leads to a website
I am trying to create a batch file (or some other file) to show a pop up reminder with a yes/no option that I can get set up to run at a designated time in task scheduler. This will be planned to run ...
0
votes
0
answers
60
views
Where are the Hardware Address / Device Files listed in Windows 10? (McAfee Solidifier CLI commands/Win10 in use)
Our company uses McAfee Solidifier to lock down our Terminal PC's. I've been looking to find the minimum required folder(s) to re-solidify in order to allow newly attached peripherals to work and I'm ...
0
votes
1
answer
154
views
"dir like" sorted by time in a batch file (.bat) using a piped string command: Get-ChildItem | Sort-Object -Property LastWriteTime, not working
I'm trying to build a trivial batch file in Windows for command line to execute a "dir like" command to list the directory contents sorted by time, avoiding typing: Get-ChildItem | Sort-...
0
votes
3
answers
211
views
Batch script to take first & second part of folder name and create new folders from them
Any wizards out there that can help with this?
I have some music folders labelled like this "Taylor Swift - 1989" etc with just the music files and folder image in the one folder.
I need ...
0
votes
1
answer
384
views
run batch file during Windows Setup from autounattend.xml
I want to run a batch file during the windowsPE phase of an unattended Windows setup, and the autounattend.xml works fine as long as I launch the batch file from its path like this:
<...
0
votes
2
answers
614
views
How to close cmd windows when I execute a batch file
I tried making a quick RDP connection as a batch file with ID, password, etc....
And I found this article:
How do I make a shortcut of a remote desktop connection and include the password?
From user: ...