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.

learn more… | top users | synonyms (1)

31
votes
3answers
70k 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?
19
votes
4answers
68k 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 :- ...
15
votes
3answers
63k 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 ...
11
votes
8answers
2k 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 ...
9
votes
5answers
922 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. ...
8
votes
7answers
20k 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 ...
8
votes
5answers
16k 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.
7
votes
2answers
6k 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, ...
6
votes
2answers
341 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 ...
5
votes
4answers
11k 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 ...
4
votes
1answer
6k 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 ...
4
votes
5answers
2k 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 ...
4
votes
2answers
6k 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 ...
3
votes
2answers
152 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
5answers
4k 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 ...
3
votes
2answers
2k 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 ...
3
votes
1answer
17k 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
5answers
1k 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
5answers
312 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
6answers
2k 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?
3
votes
1answer
526 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
1answer
809 views

Why does robocopy take 8 hours to transfer one files that is 70-80gb?

We have a scheduled task that runs every night and copies a file of around 70-80gb from one server to another on our network. For some reason it has been taking ~8 hours to do this, which is a problem ...
2
votes
3answers
745 views

Using a for loop in Microsoft cmd.exe, how can I process only the files with a certain extension?

I have a the folder c:\test\ and two files in it a.txt and b.txtv. I would like to process just the files with extension equal to .txt. If I write this commands cd c:\test for %f in (*.txt) do echo ...
2
votes
2answers
364 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 ...
2
votes
5answers
7k views

How do I redirect/save the console to a file and keep it visible on the screen?

I want to save a program's output (stdout) to a file but still be able to see the output on the screen in realtime. I need a solutions for both Linux and Windows.
2
votes
3answers
2k 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?
2
votes
2answers
822 views

using xcopy or copy to back up files?

I have a local drive that contains a directory per user: c:\user1\ c:\user2\ c:\user3\ and I have a remote drive (via a share) that contains the same directory tree: f:\user1\ f:\user2\ f:\user3\ ...
2
votes
2answers
6k 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: ...
2
votes
1answer
97 views

How to remove directories using wildcards by reading a file using batch?

Batch file for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f" PAUSE exit 7profiledeletelist.txt C:\Users\1* C:\Users\2* C:\Users\3* C:\Users\4* C:\Users\5* C:\Users\6* C:\Users\7* ...
2
votes
1answer
251 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 ...
2
votes
4answers
613 views

What is the efficient way to backup large files?

I have the schedule job of backing large files in Windows Server and it takes almost 2 hours to finish. For now, I only use copy command in the .bat and copy the large files to another folder. I'm ...
2
votes
3answers
483 views

I need to clear out the same directory on multiple servers across a network. How do I do this?

On multiple (about 20) servers, there exists the same directory C:\Deployments. This directory has multiple subfolders which contain more subfolders and files. The C:\Deployments directory itself ...
2
votes
3answers
2k views

How to put DayOfWeek value into file name?

I would like to use the numerical part of the output of "wmic path win32_localtime get dayofweek" to number backup files. Something along the lines of: FOR /F "tokens=2 delims=\n" %%DoW IN ('wmic ...
2
votes
2answers
1k views

Batch file to call multiple batch files and keep going after errors

I have a batch file like this, the issue that I have is that if the first batch file fails, the second one never gets started, how can I get them to both keep going? @echo off MapNetworkDrive_J.cmd ...
2
votes
1answer
902 views

Batch - how to copy file by minimum size and date modification?

I have this simple batch script which copies the newest file in some dir to another place. I want this script to also ignore all files (in the DIR command section) under 1GB of size. FOR /F ...
2
votes
1answer
187 views

Powershell script on the hidden file share not accesible on the workstation

We have a PowerShell script script.ps1 on a hidden shared folder \\Server\Share$. We have a bat file Initiator.bat, which executes the script. The shortcut to the batch file is placed on the user's ...
2
votes
1answer
165 views

How do I run bat file inside cmd using tash scheduler

How do I run bat file inside cmd using tash scheduler. I've tried this one C:\windows\system32\cmd.exe C:\synchronization.bat And doesn't working.
2
votes
1answer
86 views

I'm having trouble finding these commands to run in a batch file?

I want a batch file to pull information from the first line of a text file (notepad), use that information to add information to a DNS server, and then delete it. I'm thinking if I create a loop, I ...
2
votes
1answer
5k 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 ...
2
votes
2answers
1k views

Execute a remote command on a Mac from Windows

What's the easiest way to execute a single command on a Mac from a remote Windows machine, via batch? I would like something that works without a preset configuration (like SSH credentials) on either ...
2
votes
2answers
1k views

Setting Variables in Windows Batch Scripts

I need to set some variables based on an argument for a windows batch script. @echo off if [%1]==[] ( echo "Usage: xxx <AAA|ZZZ>" ) else ( if [%1]==[AAA] ( SET ...
2
votes
2answers
338 views

simple script to backup PostgreSQL database

Hello I write simple batch script to backup postgeSQL databases, but I find one strange problem whether the pg_dump command can specify a password? There is batch script: REM script to backup ...
2
votes
1answer
791 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 ...
2
votes
1answer
148 views

batch - File last modification time with seconds

I want to know when a file has been modified for the last time. I can get these infos using the following batch script: FOR %%i IN (myfile) DO SET modif_time=%%~ti The problem is that I need ...
2
votes
1answer
553 views

Checking .BATs exit code with NAGIOS?

I currently have the following script on a Windows Server: @echo off set path=%PATH%;C:\UnxUtils\usr\local\wbin cd /D Z:\videos forfiles /M *_1.mkv /D +%date% > C:\mkv.txt >NUL 2>&1 ...
2
votes
1answer
473 views

How does the “Last Result” column of Scheduled Tasks in Windows Server 2003 get set from a process or script?

The Last Result column of the Scheduled Tasks Window on Windows Server 2003, displays the result of the execution of the .exe, .vbs, .ps1, .bat, .cmd, etc... that has been run at the scheduled time. ...
2
votes
1answer
1k views

Dos Batch File Help: Storing %%c variable from FOR loop [Resolved]

It's been a while since i've had to write a batch file, and i'm having trouble with the following: @echo off SETLOCAL ENABLEDELAYEDEXPANSION for /f %%a in ('dir f:\*mssql* /ad/b') do ( for /f %%b ...
2
votes
1answer
972 views

VboxManage in a Batch File

I have the command below in a windows batch file, whenever I run the above batch (ipconfig.bat) to get the ip of my linux vm, it outputs the ip fine but doesn't ends the batch file, I have to press ...
2
votes
2answers
3k views

Executing batch file from sql server job

I want to create backup job on sql server. And i want to execute batch file in job. I just wonder the part of executing batch file from sql job. Do you have any idea? Any help would appreciated. use ...
2
votes
6answers
955 views

PHP vs Batch file for mysql cronjob?

My server details: OS: Windows Server 2003 IIS6 Plesk 8.xx installed (currently using Plesk to set the cronjob) I need your advice. I have 2 methods: Method 1: Using php + mysqldump, create ...