Windows Batch





Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

Share tech news, updates, or what's on your mind.

Sign up to Post

I have a text file in 2 columns where column 1 is date in dd/mm/yyyy while column 2 is a user's name.

11/12/2018         aaron
28/12/2018         amber
5/1/2019              ben
2/11/2018            barney
2/1/2019              carl
. . .

Need a Windows batch script (not PowerShell) that when I run today (say it's 18 Jan 2019 today), would lik eto
extract out a list of users where the date in the file is more than 31 days from today's date.  So output will be:

11/12/2018         aaron
2/11/2018            barney
need a script to deploy multiple windows updates using a group policy.

1. I will place the following updates on a file share for example: \\\updates\. I need a script or a batch file that I will publish using a group policy to deploy the updates on my windows 7 client computers. these updates are for windows 7 64 bit clients only.

2. the updates I want to install are like below located in the \\\updates\ folder.


3. I need a batch file that can trigger the deployment in sequence one after the other.
4. if the update is already installed it should skip and move to the next update.

there are some scripts I found but not working. appreciate any help
Hi All,

I am running into problem where I need to open a folder using a batch file.  I have tried start option but due to spaces, I am not able to open the folder.  There are 2 folders one with 2 spaces and one with 3 spaces.

Start C:\Folder1\Folder2\Test Name\ Final test name\test.txt

Once the batch file is complete, I need to write the file name into a text file. Please advice.
I have a PowerShell script which checks to ensure certain backups have taken place. The script checks the date of certain flag / semaphore files and shows a message if the files are too old (which one is in this test)

This works fine when manually run from the following batch file
Powershell.exe -executionpolicy Bypass -File  "Check-If-Backup-Failed.ps1"

Open in new window

but not when the same command line is added to the 'logon.bat' logon script.

What am I doing wrong (I presume it is permissions somehow) ?

NOTE: I don't get an error when I login - it just does nothing.
Hello Expert's,
Need a batch scripts:-

We have an application which is generated a log file in txt format (d:/OF Top/logs.txt), once application generate new log that happen added to that txt file. It happens so often, txt file have info in the term's of user identity number.
e. g.
11345, TOP, BLACK, TOPIC11, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC81, 110067155, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, LOGIC00, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, MAGIC99, 110067105, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC89, 110067110, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, ARPIT67, 110067100, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, MANIS56, 110067110, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, WHITE00, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, ACERP23, 110067155, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC89, 110067105, DBEN, EXCEL, 11:33:54, LOCK

Column number 5 have user Identification numbers.

There are many such lines store in this file.

Now i want a batch when I run the batch file then batch ask me to place user identity number to grep that particular user identity number and generate a txt file in a prefix location (c:/out. txt)

after that once new entry came to this file it will automatically grep that entry & store (add) in to out.txt file.
I have a text file which has duplicate lines... I need to remove any dupes and leave just one of them. The file also needs  2 different strings of words replaced with different strings of words IF either of the 2 original strings exist.

Is this even possible via Windows batch?
This is an intention to run a batch file from the usb thumb drive when this thumb drive plug into the desktop or laptop. Targeting MS WIndows  7/10/2008/201. Please see the contents of the autorun.inf as follows,


The "autorun" didn't seem to fire up.  How to get this automatic function works?

thanks in advance.
Hi Folks,

I'm creating a batch script here to allow RDP on Windows
powershell "Set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\‘ -Name “fDenyTSConnections” -Value 0"

Open in new window

If I run this script will get me an error :
set-itemproperty: a positional parameter cannot be found that accepts argument

But if I was to copy paste the line above to the DOS console they it would work like a charmed.

Have anybody experienced similar or same issue?
.bat file:

:: Get FTP files
rem ECHO Getting FTP files...

rem "C:\Program Files (x86)\coreftp\coreftp.exe" -s -O -site ISI -d /*.zip -p "F:\TeamDB\New backups"

ECHO Extracting zips...
fastzip -x -overwrite=always "F:\TeamDB\New backups\" .
fastzip -x -overwrite=always "F:\TeamDB\New backups\" "F:\TeamDB\New backups\ISIFiles"


set DBDIRECTORY=F:\ISI Databases
::rem set DBDIRECTORY=D:\Databases

ECHO Restoring %DBNAME% Database

osql -S ISI-SQL\ISIDB -E -d master -Q "alter database [%DBNAME%] set single_user with rollback immediate"

:: rem osql -S ISI-SQL\ISIDB -E -d master -Q "restore FILELISTONLY from disk='%~dp0\%DBNAME%.bak' "

sqlcmd -S ISI-SQL\ISIDB -E -d master -Q "restore database [ISP-MIS] from disk='%~dp0\ISP-MIS.bak' WITH MOVE 'R%DBNAME%_Data' TO '%DBDIRECTORY%\%DBNAME%.MDF',  MOVE 'R%DBNAME%_Log' TO '%DBDIRECTORY%\%DBNAME%_Log.LDF', REPLACE "

::rem osql -S ISI-SQL\ISIDB -E -d %DBNAME% -Q "sp_grantdbaccess '%COMPUTERNAME%\ASPNET'"
::rem osql -S ISI-SQL\ISIDB -E -d %DBNAME% -Q "sp_addrolemember 'db_owner', '%COMPUTERNAME%\ASPNET'"

osql -S ISI-SQL\ISIDB -E -d master -Q "alter database [%DBNAME%] set multi_user"

Open in new window

The above is a .bat which works perfectly when actioned manually and it updates my SQL database
If I set up a scheduled task, the task runs but the file does not work through all of the scripts and the sql database is NOT updated
I have tried many different ways of setting up the scheduled task but no result
Suggestions please

We are trying to push a login script using the GPO. The script is to copy the default folder of Google from the roaming profile to the local AppData. It is an Xcopy command. I have converted it into a batch file and copied the batch file to the netlogon and sysvol folder. The GPO is applied but does not run the batch file.

The batch file works by itself and also when we copy the batch file to the startup folder in roaming profile it works. All the other policies are working except this.

We use windows 10 and Server 2012 r2

Please provide any advise.


In IPSwitch ftp professional 12.6

I have a scheduled task that transfers files from a customer FTP to my local folder
Works fine
I have delete access on the customer folder

What I need is Post transfer... after that task has run

Sometime later

I need to delete the files in the customer FTP

I don;t care if I need to include it in the current scheduled activity

Or create a new one that runs an hour later

This runs only once a day
I have a text file being created nightly in a network shared folder. That file has many lines including 3 duplicates. The line duplicated 3 times is:

ACCNT	Accounts Receivable - MU	OCASSET

Open in new window

What I need to do is, from within an Access function, delete the 2nd and 3rd dupe, leaving the first one intact.

Why the dupes exist is a rabbit hole that I don't right now have time to fix even though yes, that is the correct way to really fix this problem. But, if I can just have Access code which will delete the 2nd and 3rd entry of that line, it will suffice as a solution for now.

Thank you very much for any input.
Rundll32 command runs fine at the command prompt but does not execute in a batch file. Any idea why?

this is the command:

rundll32 printui.dll,PrintUIEntry /in /n\\printers\105-XE-ECOM-BW1

\\printers                      is the print server name
105-XE-ECOM-BW1     is the name of the printer
Good afternoon,
I'm need some help with a script I'm using to clean up the profiles on the public pc's. I need to add some code to remove .bak files from the profile list. particularly this one, S-1-5-21-3822824043-2368925748-477173625-1177.bak For that matter, I could use a totally different script but I would prefer to just add it to this one.


FOR /F "tokens=*" %%a IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"^|FIND /I "S-1-5-21"') DO CALL :REGDELETE "%%a"

FOR /F %%b IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "internet"') DO REG DELETE "%%b" /F
FOR /F %%c IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "TEMP"') DO REG DELETE "%%c" /F
FOR /F %%d IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "short"') DO REG DELETE "%%d" /F
FOR /F %%e IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "jobseeker"') DO REG DELETE "%%e" /F
FOR /F %%f IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "catalog"') DO REG DELETE "%%f" /F

FOR /F %%b IN ('DIR C:\Users /B^|FIND /I "internet"') DO RMDIR /S /Q "C:\Users\%%b"
FOR /F %%c IN ('DIR C:\Users /B^|FIND /I "TEMP"') DO RMDIR /S /Q "C:\Users\%%c"
FOR /F %%d IN ('DIR C:\Users /B^|FIND /I "short"') DO RMDIR /S /Q "C:\Users\%%d"
FOR /F %%e IN ('DIR C:\Users /B^|FIND /I "jobseeker"') DO RMDIR /S /Q "C:\Users\%%e"
FOR /F %%f IN ('DIR C:\Users /B^|FIND /I "public"') DO RMDIR /S /Q "C:\Users\%%f"
FOR /F %%g IN ('DIR C:\Users /B^|FIND /I …
Hello experts,

i am in need of a script that can copy a file on a daily basis from one directory to another based upon a changing filename. The filename's base stays the same, however the current date is appended to the end of the file.

For Example:
StaticFileName<Today's date in MM-DD-YYYY format>
StaticFileName12-17-2018    <-----This is the filename that needs to be copied on 12-17-2018

I am not a scripting expert so suggestion on best method (powershell, batch etc) is also appreciated.

Thanks in advance.

I'm trying to run a batch file from a SQL Script but error occurs.

EXEC xp_CMDShell 'C:\Users\Simon\Desktop\Stadium\Stadium Insert\Integration Services Project7\refresh.bat'

'C:\Users\Simon\Desktop\Stadium\Stadium' is not recognized as an internal or external command,
operable program or batch file.
Hello experts,

I have the following bat file which allows me to open automatically multiple tabs.
I would like to add the following requirement:

@echo off

SET BROWSER=chrome.exe
START %BROWSER% -new-tab "url"
START %BROWSER% -new-tab "url2”"

Open in new window

Instead of reporting url I would like to loop a url.txt which contains the various urls.
Error checking:
If url.txt file doesn’t exists
I had this question after viewing List folders and sub-folders of a path with its size.

I need to take this a step further.  I need to be able to search for file types like .mdb, and ,accdb..
Then output data to a text file I can link to.  
All the code I have inserts into the same worksheet, but this keeps crashing my computer.

Ideally I would like to include:
Sub Folder
Last Modified By or Owner (Not sure if possbile)
Date Last Modified

Exported to a text file.  

We have an insane amount of access databases, I need to do a formal audit to gain an insight of what is out there, size and when used last.
hello all,

I have a batchfile to check version from text file, if it matches do something for now

cmd.exe /c type \\version.txt | find /i "14.56"

if it matches to version in text file dont do anything, if it matches run following command

cscript.exe Messagebox.vbs "STOP"

if it doesnot matches run

cscript.exe Messagebox.vbs "Success"

For some reason, I can't get my Windows batch script to read a file.   The file exists...I've checked a million times. The path is correct...I've checked a million times.  

Yet it does not enter the "for" loop.  If I put double-quotes around the %DataElements%, it goes into the For loop just fine and prints the value of %DataElements%.  I paste that value in the CMD window and up pops the file.  It doesn't make sense.  

@echo off
setlocal enabledelayedexpansion
set DataElements=E:\myDir\Data_Elements.txt
for /f "tokens=*" %%a in (%DataElements%) do (
      set line=%%a
      echo line is !line!

What the heck?!
Need better solution for backing up data to a network drive.  Powershell or batch script is ok, just the logging is less than desired.  Needs to be able to run on Windows server OS and handle large amounts of data (2 TB - 8 TB).  

FreeFileSync and SyncToy were great applications that worked well for this simple purpose.  Make a folder pair and configure the kind of sync between the folders.  I am fine doing in a script, just do enjoy the ease of use there.
Using Windows Batch Scripting, I'm working to pull certain strings from an error log so I can build a SQL Statement.  

So far, I've gotten what I need into a file on one continuous line.  It should be that way each time I pull in an error.  I'm interested in pulling out only the UPDATE statements and certain elements related to each one.

The line may contain one or several INSERT, UPDATE or DELETE statements peppered throughout so it's very tough to decide what to search for.  

As I pull in the strings I want for each UPDATE statement, I'll build the SQL and call a stored procedure to do what I need to do.  Then return to the Batch Script to get the next UPDATE statement (if there is one).

I've already managed to get a Count of the number of UPDATE statements so I can use that for a loop.

The line below is an example of what I've managed to place in a file (all one continuous line).

} SQL Exception (state )(using SQL: "[UPDATE owner.tableName SET i_unwanted_column1=yyyy,i_unwanted_column2=yyy,i_unwanted_column3=yyyyy,d_unwanted_column4=to_timestamp('1900-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = yyyyy , UPDATE owner.tableName SET i_unwanted_column1=xxxx,i_unwanted_column2=xxxx,i_unwanted_column3=xxxxx,d_unwanted_column4=to_timestamp('2018-10-29 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = xxxxxx ]"):

I need to extract the "owner", "tableName" (found after the UPDATE), the primary key column name and it's value…
I'd like to use a batch file to sum some specific numbers in a text file, unfortunately I do not have the skills required. In the following text file "test.txt", for all rows beginning with "622..." I need the second block of numbers summed together and put in a line after the last "622..." line. The total must retain any leading zeros so that the result will always be 15 digits long. It should also line up with the spacing of the values above it. The first number in the total line is a constant, as is the “COMPANY NAME”. At the end of this total line, the “00724…” number should maintain the chronological order of the one above it.

Original txt file:

101 123456789123456789123456789123456789BANK NAME              COMPANY NAME                   
5200COMPANY NAME                        1234567891CCDPAYMENT   123456789123   1072414250000001
62202123456789123456789      000056998811365          CHEMICAL MASTER LTD     0072414250000001
622021321321456987568        000149897016984          CHEMCO USA INC          0072414250000002
622011233214569874563211     000017285016585          GUME INC                0072414250000003
6220225411123658954212       000270139112936          DIOVIK GROUP            0072414250000004
6220432211655548541232       000000632017155          SANVED ENTERPRISES      0072414250000005
820000000500112340500000000000000000497895191123456789                         072414250000001

Open in new window

Around 350 pc and servers running windows os, how to  generate windows patch update status report of those pc & servers, information such as last update date, patch installed. powershell script or other ways to generate the report?

In order to backup properly my SQL Database I need to create 2 batch files which will run on 2 scheduled task and will do the following tasks

1)      Daily at 23h PM : STOPSQL.BAT : Stop SQL SERVER Service and Stop SQL Server Agent Service
2)      Daily at 6h AM: STARTSQL.BAT: Start SQL SERVER Service and Start SQL Server Agent Service

What is the recommended solution for the content of these 2 batch files?
Thank you

Windows Batch





Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.