Questions tagged [batch]
A batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter under MS-DOS and Microsoft Windows.
342
questions
199
votes
5
answers
625k
views
How to sleep in a batch file?
How to pause execution for a while in a Windows batch file between a command and the next one?
62
votes
7
answers
165k
views
Windows command prompt: how do I get the output of a command into a environment variable?
I want to have an environment variable that contains the day of week in cmd.exe.
When I run this command I get the result I want.
C:\Users\tisc> powershell (get-date).dayofweek
Friday
Here I'm ...
40
votes
4
answers
154k
views
Get directory containing the currently executed batch script
I use %0 in batch file to get the containing directory of the batch file but the result is :-
c:\folder1\folder2\batch.bat
I want just directory, without batch file name, like this :-
c:\folder1\...
38
votes
3
answers
333k
views
For Loop counting from 1 to n in a windows bat script
I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line :-(
I would ...
26
votes
13
answers
104k
views
Need leading zero for batch script using %time% variable
I came across a bug in my DOS script that uses date and time data for file naming. The problem was I ended up with a gap because the time variable didn't automatically provide leading zero for hour &...
26
votes
7
answers
104k
views
How to create a never expiring password & user via net user through .bat file
I am using a .bat file to create a user and password at windows operating system level.
The issue am facing is when i pass EXPIRES:NEVER for password, when the user is created, it doesn't have "...
24
votes
4
answers
39k
views
Locale-unaware %DATE% and %TIME% in batch files?
The %DATE% and %TIME% environment variables provide the current date and time on Windows machines on the command line and inside a batch file.
Sadly, those values are locale-aware! Meaning that, say, ...
20
votes
4
answers
51k
views
How do I extract all archives in the subdirectories of this folder?
How do I extract multiple archives in contained in subdirectories in a folder, outputting the results back into the folders where the archives are.
19
votes
3
answers
105k
views
call batch file and run using its own path/directory
I have a batch files that calls other batch files like this:
e:\foo\master.bat has the content:
call e:\bar\run1.bat
and e:\bar\run1.bat has the content
app1.exe
the problem is that when I run ...
13
votes
8
answers
71k
views
Program does not run properly as Scheduled Task
Situation
I have a batch script that prepares some files, executes a program (.exe) and then deletes said files.
This task should run hourly, so I'm trying to configure this using Scheduled Tasks. ...
12
votes
8
answers
10k
views
Expire Files In A Folder: Delete Files After x Days
I'm looking to make a "Drop Folder" in a windows shared drive that is accessible to everyone. I'd like files to be deleted automagically if they sit in the folder for more than X days.
However, it ...
10
votes
23
answers
128k
views
Finding day of week in batch file? (Windows Server 2008)
I have a process I run from a batch file, and i only want to run it on a certain day of the week.
Is it possible to get the day of week?
All the example I found, somehow rely on "date /t" to return "...
9
votes
1
answer
3k
views
Shutdown script doesn't run if workstation is not connected to the network
I have a requirement to run a batch script every time a system is shut down, no matter if the computer is connected to the network or not. (It shouldn't matter for the question, but the script in ...
9
votes
3
answers
64k
views
How can I create an ODBC connection from .bat file in Windows?
I need a batch script to create an ODBC/DSN connection from a .bat file in Windows. How can I do this?
8
votes
4
answers
7k
views
Determine if C drive has 2 GB of free disk space
I am trying to determine if a target pc has atleast 2 GB of free space. Here is what I have so far:
@echo off
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='C:'" get ...
8
votes
3
answers
18k
views
Evaluating expressions in windows batch script
This one could turn out as the dumbest question ever, as I am probably missing out the obvious. Anyway, here it is: Can you evaluate expressions in a batch script. For example, I want to add two ...
7
votes
1
answer
16k
views
Can I permanently add to PATH in windows using batch?
Is it possible to permanently add c:/project/bin to PATH i windows using only batch?
7
votes
2
answers
14k
views
delete registry key using wildcards
I'm hoping to find a way to delete registry keys based on wildcards using a batch file rather than writing some vbscript. Does anyone have an example?
I'm forced to proceed with MS's wonderful manual ...
6
votes
1
answer
5k
views
Is there a cmd/certutils to copy a certificate from one store to another?
I would like to know if there is a cmd to copy an existing certificate from one store to another. I am trying to copy a certificate from the Users Intermediate Certification Authorities store (...
6
votes
6
answers
6k
views
shortcut for Eventvwr > Connect to another computer
I was wondering if you can write the following action in a batch command?
eventvwr (open the event viewer)
Menu Action > Connect to another computer
Type in the name of the computer.
Connect.
This ...
6
votes
1
answer
11k
views
PowerShell: export GPO to a text file
I'm new to Windows Server, and I'm curious: is there any way to dump group security settings to a text file, using PowerShell or batch files? Thank you!
6
votes
2
answers
20k
views
Checking if shared folder exists using CMD
How I could check if network folder shared exists using batch script?
Example: \\10.10.10.1\folder1\folder2\shared_folder
5
votes
6
answers
20k
views
Is there a way to submit a batch of commands to a Cisco router and have them execute from the router?
I need to change the configuration of a remote (6 hours' drive) client's Cisco 871 (IOS 12.4.15T) from my location because of some new internet service at his location. To be more precise, I need to ...
5
votes
7
answers
6k
views
Batch scripting: iterate over drive letters?
In windows batch scripts, how can I iterate over all drive letters which correspond to physical volumes or mapped shares?
5
votes
2
answers
29k
views
rsync unexplained error & received SIGINT, SIGTERM, or SIGHUP
I created a batch script to back-up our server:
#!/bin/bash
user=$1
# create user dir
ssh [email protected] -p 5774 mkdir -p /var/backup/server.tst/incremental/$user
# backup mail dir
rsync -...
4
votes
2
answers
62k
views
Check free disk space using Batch commands
Is there a way already to check the free space of a hard drive in a batch script?
I'd rather not use third party apps since I need to fill out a lot of forms, and in that case I think I'll write a ...
4
votes
4
answers
61k
views
Start GPO script as administrator
I need to install a software using a login script, which is distributed by the GPO.
Currently it is starting, but it is not run as an administrator, so the installation is not done.
How can I make ...
4
votes
2
answers
2k
views
Is there a way to change passwords on multiple servers simultaneously?
x3 Server 2012 R2, x2 Server 2012
My system has 5 servers; 1 Hyper-V server hosting 2 vm servers (these are the x3 2012 R2 servers), and a Win 8.1 pc running hyper-V that hosts 2 more vm servers (...
4
votes
2
answers
5k
views
Batch rename directories with regex via command line on Linux
I have a folder on the server that contains directories that are created daily and are named by date, like so:
07-06-14
08-06-14
09-06-14
etc.
At some point I decided that a preferred naming would ...
4
votes
3
answers
7k
views
keep command window open after running bat file
i have a bat file that has the following it:
sm start "Schedule"
this code runs but the command window closes immediately
what can i put inside the bat file to keep the window open?
4
votes
1
answer
19k
views
Batch script to test if a folder exists fails when checking a UNC path
I've written a small batch file to help us with a server migration to remap user directories using GPO.
However in the batch file I'm having a syntax problem that appears right but it's still failing....
4
votes
1
answer
18k
views
Get PowerShell command output as a variable in bat (cmd) script
I'm trying to get FQDN of a host in some .cmd file. We have disjointed AD domain so "@echo %COMPUTERNAME%.%USERDNSDOMAIN%" does not work. I mean it works, but returns wrong value.
The solution I ...
4
votes
1
answer
198
views
Batch Process Performance on Linux
My end users wants to run batch processes concurrently on a Linux box. Their impression is that running multiple of them at same time will reduce turnaround time. These processes do fair amount of ...
4
votes
1
answer
3k
views
How to restart atd without affecting running jobs?
Does anyone know how to restart atd without affecting current running (batch) jobs?
I guess I could move the jobs out of the spool directory and wait for the current running jobs to finish, but I'm ...
4
votes
1
answer
28k
views
Script for renaming files and adding a timestamp (server 2012 r2)
I'm struggling to create a (fairly simple) batch file script that meets these requirements:
Looks in the folder called Source for a file (with any name.csv)
Renames the file to ...
3
votes
10
answers
7k
views
Batch processing on Linux
We're currently setting up a server to some heavy lifting (ETL) after another process has finished within the business, at the moment we're firing off jobs either via scheduled cron jobs or remote ...
3
votes
2
answers
617
views
Make windows all in capitals for specific application
Is there a method where I can set windows transparently to caps preferrably when a specific application is run. For bonus points, I should be able to revert back to normal (non capslock mode) when ...
3
votes
6
answers
10k
views
Windows Batch - Get name of currently logged-in user
In a sort of small mitigation for a large network for the exploit of replacing utilman.exe on windows repair, by cmd.exe, then changing user password, I'm doing a small script based on EventSentry ...
3
votes
2
answers
26k
views
cmd.exe: how to start a background process, run some things, stop background process
I want to run a batch script that:
starts a background process (a Selenium RC server, if that matters);
waits until the background process starts to listening some port (or wait a fixed amount of ...
3
votes
3
answers
3k
views
How to get all processes under a session of a particular process that is using a port in Windows cmd
I want to list and kill all processes belonging to a session of a particular process that is using a port. This should happen through a windows batch command that would accept a port number as input.
...
3
votes
5
answers
2k
views
Web interface for torque
Can someone recommend a good web interface for Torque? I'm interested mostly in monitoring the status of the job queues.
3
votes
2
answers
29k
views
Adding numbers stored in variables in windows batch script
I have a loop in a batch script and I would like to do some arithmetics with the loop counter. I found out how to evaluate expressions, how to add numbers here: Evaluating expressions in windows batch ...
3
votes
2
answers
20k
views
Robocopy - All data marked as modified
We make use of the following script to backup a folder (quite large - approx. 400GB), to a NAS with EXT4 Filesystem:
robocopy "Source_Directory" "\\NAS\Destination\Directory" /MIR /FFT /COPYALL /W:5 /...
3
votes
5
answers
995
views
del *.txt removes also file.txt_backup
Imagine that we have directory c:\test with following files:
first.txt
second.doc
third.txt
fourth.txt_bak
I want to remove only txt files, but leave doc and txtwhatever untouched.
When I run ...
3
votes
1
answer
32k
views
Microsoft Intune - How to modify Windows 10 registry settings?
Win32 app uses bat file to install software and edit registry keys. Registry keys are modified if I run bat file locally but not when run through via Intune because Intune runs installation as System.
...
3
votes
1
answer
7k
views
Can't run .bat file off share, but can from cmd
I have a smb share on a Linux box set up that I can view in explorer:
\\XXX.YYY.ZZZ.QQQ\Share
In this share is a batch file:
\\XXX.YYY.ZZZ.QQQ\Share\Scripts\Script.bat
I can open the file in ...
3
votes
1
answer
5k
views
Trouble using powershell output as a variable in batch file
I can manually run this command from a Windows Command Prompt:
powershell (new-timespan -start 01/01/2000 -end (get-date)).days % 14
And it returns a number from 0 to 13. I want to use this result ...
3
votes
1
answer
5k
views
wevtutil requires Run As Admin for Security log (but not for System), or how to Run As Admin for Task
I'm using this query to check for certain Exchange account changes on my Windows 2008 R2 AD primary:
wevtutil qe Security /q:"*[System/EventID=5136]" /f:text /rd:true /c:1
I'm making a batch file ...
3
votes
1
answer
717
views
trying to copy security groups to a user using dsmod group utility in AD
I am trying to create a batch file that asks to enter source samid and destination samid. Then using dsquery and dsget find out what security groups source samid is assigned to and assign destination ...
3
votes
1
answer
18k
views
Split string line read by a batch file
is there a way to "split" the value of string line readed by a batch file ?
Suppose to have this text file
192.168.1.2; PC_NAME_1
192.168.1.3; PC_NAME_3
...
I would like to read line 1, and split ...