Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Need to change WIFI properties to metered, on a group of laptops. Hoping for a batch file, or small script, an assistant can run on each. Hard drives are too small for Win 10 auto updates, attempting to stop auto download of them, so we can do them in a controlled, scheduled fashion, instead of when students are trying to use.
Ask an Anonymous Question!
LVL 10
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

I received an excellent response to my question of deleting files based on match and amount of days old.   Initially I was told they should delete based on age of file and if they have a matching .xxx file.    That has since changed to:   files should delete based on if there is a matching .xxx file and only if it is older than 3 days (regardless if the other files are older).  

The script help I received before from Bill Prew looks like:

@echo off
setlocal EnableDelayedExpansion

rem Define folder to process
set "BaseDir=C:\Users\ad9f2p\TEST CLEANUP"

rem Look at each .XXX file
for %%A IN ("%BaseDir%\*.xxx") do (

  rem Reset delete flag, and check all files with this same base filename
  set DeleteFlag=Y
  for %%B IN ("%BaseDir%\%%~nA.*") do (

    rem Get dyas since last modified (using VBS helper routine)
    set Fileage=0
    for /f "tokens=*" %%C in ('cscript //nologo fileage.vbs "%%~B"') do (
      set Fileage=%%C

    rem If any file found less than 3 days old, do not delete the group
    if !FileAge! LEQ 3 (
      set DeleteFlag=N

  rem If all files found older than 3 days, delete them all
  if "!DeleteFlag!" EQU "Y" (
    ECHO del /q "%BaseDir%\%%~nA.*"

Open in new window

Can I add a nested If statement to the section:

    rem If any file found less than 3 days old, do not delete the group
    if !FileAge! LEQ 3 (
      set DeleteFlag=N

Open in new window

Can I check the file age on only the .xxx files and delete the corresponding files that match then, only if the .xxx file is older than 3 days?   I've tried doing this by rearranging the logic, currently it deletes everything with a .xxx file:    What am I missing here?

Open in new window

I have a timestamp field named quote_created for when the record was created. I also have a field named send_email in that record.

If the quote was created more than ten minutes ago AND send_email=1, I need to be notified via email. We have Exchange 2007.

Can I display a message on the screen  while a batch job is running?
"Job still running...."

then when done

"job completed!"
need a script to press ok or enter or any key when this message appear on desktop,is possible?
see capture.1 jpeg
i need a batch script to press and open START Menu wait 15 sec. and then close START menu
Hi Experts,

I need to parse "Sql Developer" history. That history is retained in a dir under appdata as xml files and looks like this:

<?xml version='1.0'  encoding='UTF-8' ?>
                                <sql><![CDATA[update epd01 set monres_fis_2 = '1,47' where numcpt = '103521560782' and monres_fis_2 = '2,94';
update epd01 set monres_fis_2 = '6,09' where numcpt = '103521723359' and monres_fis_2 = '12,18';
update epd01 set monres_fis_2 = '253,26' where numcpt = '103521738416' and monres_fis_2 = '506,52';
update epd01 set monres_fis_2 = '27,72' where numcpt = '103521762260' and monres_fis_2 = '55,44';
update epd01 set monres_fis_2 = '450,84' where numcpt = '103521762361' and monres_fis_2 = '901,68';]]></sql>
                                <timestamp><![CDATA[12/10/17 17:02]]></timestamp>

Open in new window

All files in the dir need processed (in order) and certain values redirected into a file.
"timestamp" "connection" "sql" are the values needed.

Preferably we have "timestamp" "connection" "sql" piped along in the result file if that would be possible.
Can  you please check into this? I've been looking around EE but couldn't find something spot on.

I winder if anyone could help. Does anyone has any information on this?

A batch file required to run on a folder that will move into other folders based on file name and type.

What we have are scans coming off a locally attached scanner into one folder, need to sort from there where they will be moved to with the click of a cmd file


Scans go to c:\scans

Format PDF

Sort will be filename, example car, truck, bike etc

Pre-existing folders in c:\Scans\Car, c:\Scans\truck, c:\Scans\bike

Any help would be appreciated


What does this command do
Set arg1=%1

And what would I get if I echo %1 ?
I've done some research and I know this is a common issue. There are several reasons why this could be happening. But let me lay out what the app does and maybe narrow the problem down.

I'm very newbish at programming. So much so that all the VB app does is run a batch file upon a button click.

The batch files contain a command that determines if the processor is 64bit or 32bit:


Open in new window

When I run my application in Debug mode the batch files run perfectly fine. Everything executes and completes. However, when I go to release the app and run the EXE file it seems like the batch files are ignoring the processor architecture line. The file doesn't go to the 64BIT section and just processes everything in line. Or it's not processing the 64 bit line correctly and it's going to the 32bit section.

Here is a snippet of code from one of the buttons:

Private Sub RunningButton_Click(ByVal sender As System.Object, e As EventArgs) Handles RunningButton.Click
        Dim proc As Process = Nothing
            Dim batDir As String = String.Format("\\remoteserver\software\batch_files\inhouseapp fixes\")
            proc = New Process()
            proc.StartInfo.WorkingDirectory = batDir
            proc.StartInfo.FileName = "inhouseapp Already Running.bat"
            proc.StartInfo.CreateNoWindow = False
            'MessageBox.Show("Bat file 

Open in new window

How to Use the Help Bell
LVL 10
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

how to run a .bat file as system (i need a portable tool),i can't install i have no rights,is possible?
thank you
I'd like to schedule to run a windows batch file to execute at a certain time.
What are the steps?
need some help with this batch script
I use alwaysup.exe to run my .exe as system ,here u can see some pugins:  https://www.coretechnologies.com/products/AlwaysUp/Plugins/

I decide to use this plugin:
Stop/restart your application if a specific string is found in a log file

Command Line Usage
	CheckLogFileForFatalError.exe <file-name> -e <error-string>
		[-ok <ok-string>] [-v]
	<file-name> is the full path to the file to be checked
		- Please enclose in quotes if the path contains spaces.
		- Note that this file name can contain special macro-like
		strings that will be dynamically replaced when the program
		is run. These are:
			$DAY == The current 2-digit month (01-12)
			$MONTH == The current 2-digit day (01-31)
			$YEAR2 == The current 2-digit year
			$YEAR4 == The current 4-digit year
		For example, if today is May 26 2011, then:
		will be expanded to
		when the utility is run.

	<error-string> is the error message to look for in the file
        There can be multiple error-strings, and at least one must be specified.

	<ok-string> is a message that signals that the software is ok.
        If it appears after all the error strings, a restart will not be
        signaled. An ok-string is not required but multiple can be specified.

	-v signals to produce verbose output (optional)

        Note: All strings are case sensitive.
To check if a log file located at 

Open in new window


I need to bulk rename a bunch of files.  This is a one-off thing, so I'd like to do it without installing any software if I can avoid it.

The format of the filenames is currently:



XX-String-XX is a string which can include spaces, and all are identical
NN-Number-NN is either a one or two digit number
YY-String-YY is a string which can include spaces, and all are identical
MM-Number-MM is either one or two digit number

An example would be:

ABC Limited - Project 03 - London Site - 05.doc

So that, using the above structure:

XX-String-XX = "ABC Limited - Project "
NN-Number-NN = "03"
YY-String-YY = " - London Site - "
MM-Number-MM = "05"
Ext = "doc"

The dashes may or may not be present or might be other symbols, but most would use dashes, and nearly all have the full word 'Project' but some might have been shortened to 'Proj'.

I need to shorten this example to be, say:

ABC Limited - P03S05.doc

It would be fine if I just had to run some script or command in the top level folder for each project.  It would take a while, but not the end of the world.

I am happy to get an answer using any of:

DOS Batch / Command
Linux Bash Script / Command

It seems simple, and probably is, but the answer is escaping me right now.


I am new to writing windows batch code. I am trying to remove files from a folder that are older than 3 days old but are checked before deleting to make sure it deletes all matching files. For instance...

Given the list of files, I would want the batch code to locate the .xxx file and find any matching files with the same file prefix  and delete all three when all three are older than 3 days old.

I found the following on the internet:
SET "sourcedir=C:\Users\ad9f2p\TEST CLEANUP"
FOR /f "delims=" %%a IN (
 'dir /b /a-d "%sourcedir%\*" '
) DO (
 SET "filename=%%a"
 SET "filename=!filename:*.XXX=!"
 IF "!filename!"=="!filename:_=!" ECHO DEL "%sourcedir%\%%a"

I pulled this code from the web and started to modify it, but I am struggling since I am uncertain what some of the commands/variables are doing.   In its current state, it echoed everything in the directory to delete. It should have left the 987654 files alone.

Any help would be greatly appreciated.  Thanks, Mojeaux
Can anyone provide a script (batch or VBS) that will export a reg key in non-hex format?

I need to export the contents of a reg key but it exports the result in hex format.  I need to see the text equivalent.

Export entire tree:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

An excerpt exported as:

"My Music"=hex(2):25,55,53,45,52,50,52,4f,46,49,4c,45,25,5c,4d,75,73,69,63,00

Open in new window

Need it exported as the text (how it appears when viewed in the registry):


Open in new window


How to resolve this error message. Please advise.

Error occurred during initialization of VM
Could not find agent library jvmhook on the library path, with error: %1 is not
a valid Win32 application.

how to start software.exe from a batch file?
I can do this manually like this: i open my soft.exe i click START button and run fine.
Now i want make my soft.exe run automatically from a batch script ,can someone help me ?
I have a startup script that needs to grab values from another script. (cmd files)

The variable values do not populate without delayedexpansion ( I am ok with this except for one thing)

I have a value that contains a "!" which gets lost once read with delayed expansion on - I am unable to manually adjust this value since it is dynamic.

Any ideas on how to work around this ?


net use !server!\filepath /user:!user! '!password!'

The password sometimes contains an exclamation and causes a break is there any way to handle this ?
Free Tool: Site Down Detector
LVL 10
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

When I use PsExec with a batch file residing on a remote computer that asks for the %USERPROFILE% or %USERNAME% of the remote session it always returns my username or user profile path.

How do I run this same command so that it returns the currently logged in user's %USERPROFILE% or %USERNAME% without modifying the commands in the bat file or having the user profile credentials from the currently logged in remote user.

These are on Windows 7 64-bit machines that reside within a domain.
I have a batch file I need to run in windows scheduler.


It appears that I am having issues mastering windows schedular to execute this file:

I have tried several things in the action tab:

putting in \\sharedrive\operations\daily in the Start-in block, and master.bat in the Program block. results in cannot access directory error
Putting in \\sharedrive\operations\daily\master.bat into the Program block, and got a successful error.
How do I set this up correctly so I can call UNC-bast batch files as if they were local? I realize that mapped-drives are a problem, so here I am.

Hi all,
I put together a batch file that will ping a host(s) from a file and if the host is online it will run a few WMIC commands and export the results.  I'm getting the desired results BUT also getting an additional line of data from the loop.  Any advice is appreciated!!

@echo off
setlocal EnableDelayedExpansion
rem Define output file location
set OutputFile=WMIHost2IP_Info.csv
set IpList=wmihostname.txt

rem Overwrite output file and add header line
echo "IP","SystemName","User","OS","TaniumState" > "%OutputFile%"

rem Gather all data desired
for /f "usebackq tokens=1" %%l in ("%IpList%") do (

      rem ping the ip to see if it is online or offline
       ping.exe -n 1  -w 100 %%l >nul && set ok=Online|| set ok=Offline

rem If online.....get WMIC infoto the outputfile
      If !ok! =="Online" do (
      echo %%l  is !ok!
       for /f "skip=2 tokens=2 delims=," %%a in ('wmic /node:"%%l" ComputerSystem GET Name /format:csv') do (
              for /f "skip=2 tokens=2 delims=," %%b in ('wmic /node:"%%l" ComputerSystem GET UserName /format:csv') do (
                    for /f "skip=2 tokens=2 delims=," %%c in ('wmic /node:"%%l" OS get Name /format:csv') do (
                          for /f "skip=2 tokens=2 delims=," %%d in ('wmic /node:"%%l" service WHERE "Name = 'Tanium Client'" GET State /format:csv') do (
                  rem Write merged results to output file
                  ::echo %%~l is !ok!
                  echo "%%~l","%%~a","%%~b","%%~c","%%~d">>"%OutputFile%"

I'm working with Windows Scheduler and windows batch files.

Here's what I have:

in \\SHARE\PROCESSOR\  I have three objects:
processA (FOLDER)

inside each folder I have a python executable, plus other artifacts the python code needs to operate.

I have two users:  myself and the service account.  Both AD users.

The problem is not the batch.  When I click on MASTER.bat in folder \\SHARE\PROCESSOR\ it all works.
If I use runas on the command line to start MASTER.bat, still no problem.  everything good.

My issue is with windows scheduler.

Scheduled task
The action settings are:
Program/script:  \\SHARE\folder\MASTEr.bat
Arguments and Start in are both blank.

When this is executed by Windows Scheduler.  It runs for one minute then exits successfully with error code: 2147942401

This is where I take issue because I can see the batch file plus associated python scripts in the task scheduler.  

What I need:
I need the scheduler to not lose focus on the task.  If the action takes too long, i need it to be able to stop Master.bat.

Any wisdom would be greatly appreciated.

Since installing Office 2013 in our environment, we have to manually turn off a Windows system setting, 'Animate controls and elements inside windows' due to performance issues.

System >> Advanced System Settings >> Advanced >> Performance, Settings >> under Custom, 'Animate controls and elements inside windows' check box.

Has anyone done this via batch / GPO / or any other mass method successfully?

This is for Win 7 SP1 Enterprise.
Hi Experts,

Good Day,,,

According to my work, I need to ftp files from one server to another using batchscript.I am able to do the same.
logs are getting saved into outputlog.txt file which is present in the same server path.

My requirement is ,need to send a mail with attaching outputlog.txt .
If it is successful (means errorlevel=0 ) then subject should be ftp successfully completed.And if it get failed,then subject should be ftp failed.In both the cases, log file should get attached.

Any help regarding this would be highly appreciated.
Thanks in Advance..

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.