Improve company productivity with a Business Account.Sign Up


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 mapped drives to the NAS.

Sometimes the shortcuts disappear, I've created a batch file the re-maps the drives but don't re-create the shortcuts.

What is the command to create shortcuts?
Upgrade your Question Security!
LVL 12
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.


I'm looking to create a batch script to search through folders to see if it contains certainly named subfolders and if it does find them to copy the folder ( and structure and files in them ) to a new destination.

so it would be as follows

Folder 1
 -> Folder Files
            -> in here would be files
 -> Folder Docs
            -> in here would be files
Folder 2
 -> Folder Files
            -> in here would be files
 -> Folder Docs
            -> in here would be files

so all files within each of the Folder Files and Folder Docs to be copied aswell.

Thanks in advance.
I am trying to delete a text file from all of the user profiles within the c:\Users and F:\Users on a Windows 2008 r2 server, using Del /q /f /s c:\users\%user profile%\folder1\folder2\*.txt. which does not work, and the error says path not found.   I need to delete the text file from all the users folders on the server.

how can I make it work.
Hello Experts,
How to set show windows stacked OR show windows side by side in win 7 from batch script ?
I have a batch file that runs within Windows 10 as part of a startup script (see the screenshot)

What "Script Parameters" do I need to specify so that this batch file script will run within an elevated Command Prompt?

I want to run a GPO Results on open and really want it to rewrite the file each time, but currently its just tring to write the file and gets an error.  I dont see the need to keep copies so what would be the best way to write that line?

gpresult /h \\server\Users\GPResults\%Username%.html
I am having trouble with a variable in a batch file. I am setting a variable with special characters, and having trouble getting them to print.

One of the two special characters is %. That one, I got to print by putting two of them in the variable. (aka % became %%) The other character is ^. I have seen that ^^ should work. But, it does not.

The (literal) string that should print is:

Batch file I am using:
SET location=P%%@AP[4\PZX54(P^^)7
ECHO %location%

My output is:

<Missing the ^>

Might I need to escape the ()'s somehow?
This Batch File  must copy the file as seen  in such a way if the file does not exist copy it, if it exists don't copy it.
I need a batch file that checks if a directory exists and if it does to copy the file.  I cant get this to work

If Exist "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\" goto EXISTSxpi
:EXISTSxpi copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\" "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\"

If Exist "C:\Program Files (x86)\Mozilla Firefox\" goto EXISTScfg
:EXISTScfg copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files (x86)\Mozilla Firefox\"

If Exist "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\" goto :EXISTSjs
:EXISTSjs copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\"

If Exist "C:\Program Files\Mozilla Firefox\browser\extensions\" goto EXISTS64xpi
:EXISTS64xpi copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\" "C:\Program Files\Mozilla Firefox\browser\extensions\"

If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64cfg
:EXISTS64cfg copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files\Mozilla Firefox\"

If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64js
:goto EXISTS64js copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files\Mozilla Firefox\defaults\pref\"
Windows batch scripting & Del files in multiple directories

I want to delete *.dmp & text files from within the user profiles.      “What command or commands in a script can do this ? “  Because they will be put into the Windows task scheduler for automation.

Location of the files are in the AS400 folder. This is the full path.
H:\USERS\userProfiles\IBM dump\AS400\*.dmp and *.txt.

Note: The environment is Windows 2008 r2, in an Active Directory environment.  userProfiles  contains all of the “different user folders”  who are on the network.

The problem I have been having is bad info claiming to work that is tested and Does not work.
Get expert help—faster!
LVL 12
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Working with Windows 1, 64bit.

Using a batch file from a server based mapped directory to add a couple files to a C:\Program Files\ directory.

Even logged in as local administrator I can get it done.

Following is the contents of the bath file:

Net User administrator /active:yes
cd "Documents and Settings\All Users\Application Data\Bentley\MicroStation V8i\WorkSpace\Interfaces\MicroStation"
rd /s /q "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Interfaces\MicroStation\Default"
XCopy *.* "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Interfaces\MicroStation" /E  
cd ..
cd ..
cd standards
Del "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Standards\standards.cfg"
copy *.* "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Standards"
cd ..
cd users
Del "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Users\*.ucf"
copy *.* "C:\programdata\Bentley\MicroStation V8i\WorkSpace\Users"
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd "Program Files\Bentley\MicroStation V8i\Config\appl"
Copy *.cfg "C:\Program Files (x86)\Bentley\MicroStation V8i\MicroStation\config\appl"
cd ..
cd system
copy *.cfg "C:\Program Files (x86)\Bentley\MicroStation V8i\MicroStation\config\system"

It's simple, but the last two Copy commands do not work.

As you can see from the first line, I added the "Net User" command, which worked for a while in a previous build of Win 10, but not now...

And advice would be great.

I have this batch file that checks to see if a Windows device is at work or off-site.  If at work, it uses our internal DNS, and if off-site, it uses a public DNS.  The only problem is, I'm using a ping to determine if the devices is on-site or off-site, which takes a few seconds to fail.  This would work okay if it did not have to go thru multiple NICs (3 on my devices - Bluetooth, Ethernet NIC and wireless NIC).

This batch file is set off every time a network change event happens (connection to wifi for example).  Is there a way that I could do this faster?  I'm thinking maybe I can first check if the NIC has an IP (or someway to know the nic is active), and if so, then next test if it's on-site, and finally change the DNS appropriately.  

I'm thinking the ping test is the safest way to determine if on-site or off-site because we have wireless IP addresses that are 10.x.x.x and I know some hotels and businesses use that range.  Here is currently what I have:
REM If INTERNAL_IP_Check IP is available, it will set network cards to use local DNS. 
REM If INTERNAL_IP_Check IP is unreachable, it will set to public DNS
set INTERNAL_IP_Check=""

REM --- set DNS Servers 
set DNS_SERVER1=""
set DNS_SERVER2=""

for /f "skip=2 tokens=3*" %%i in ('netsh interface show interface') do ( 
ping -n 3 %INTERNAL_IP_Check% | find "TTL=" >nul
if errorlevel 1 (
netsh interface ip add dns "%%j" %DNS_SERVER1% validate=no

Open in new window

I need a batch file created that can replace a broken backup feature of an old program. I need the batch file to look at the size of the file that will be backed up, compare it to the available space on the F: drive. If there is space, then it copies the file, if there isn't space, then it deletes the oldest file in the destination to make room for a new file.

Basically, I'm backing up one file, once per day, and just need to make sure that that the drive has space before copying. My current batch file is:
@echo off
set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4%
copy /z "C:\Program Files (x86)\Camelot3\Database\CAMDB.FDB" "F:\Camelot\Camdb_%mydate%.fdb

This is just so that I can keep multiple copies of this file
I've been trying to, create a batch script to run all batch scripts in the current and sub directory's. So far the current script only runs one batch in the current directory.

@echo off
cd /d %~dp0

for /R %%s in (*.cmd) do (
call "%%~s")

Open in new window

My apologies for any trouble, thanks in advance.
i have a webpage that is displaying .csv files
the .csv files are named 05History0418.csv "DDHistoryMMYY"
they are all stored in a folder, i then have a html page for the last 10 files
i am trying to make a batch file that will adjust the page automatically, so it would search each html file and replace the path of the last csv to the appropriate one.
@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-2%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%month%-%day%-%year%
set "d1=%day%History%month%%year%.csv"

echo datetimef=%datef%
echo %dayf%
echo %d1%


:: yesterdays date

set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YY=%result:~2,2%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "d2=%dd%History%mm%%yy%.csv"

set day=-2
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& 

Open in new window

I am using the following command, which is working great, but it is only good. per machine.

invoke-command -computer 4w68cm2 -filepath "\\server\files\temp\ToastNotificationWin10.ps1"

Is there a way to do the same command, but instead of specifying a single machine, it would "somehow" specify an entire IP block.

For example, the command is ran against machines in the 10.10.2.x network.
Is it possible to set a PowerShell script or batch file to run before a user logs into a Windows 10 computer that is a member of a Server 2016 Active Directory domain?

If so how can this be done?
if exist "%BackupPath%\%programName%\*_%date:~4,2%%date:~7,2%%date:~12," (
if not exist "%BackupPath%\%programName%\*_%date:~4,2%%date:~7,2%%date:~12," (
echo x=messagebox(zip file with latest date not avaialble)
) else (
goto :EOF

what will be the issue in the code??

poup up echo message not coming prperly.
i have a user that needs to run the chrome browser as another user.  I don't want her to have to remember the password for this user.  fyi... it is a windows domain.
I am open to using powershell or a batch file.

how would i write this in either.
fictitious information to use.
user is logged with user name    contoso\Janedoe

user needs to run chrome as contoso\johndoe  with a password of      Blueberry

i would also like for chrome to automatically open up the website

I basically need the user to have an icon somewhere that when she clicks on it.  it runs chrome as different domain credentials - hopefully without prompting her for credentials either.
Thanks guys
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I need to (transparent to users) remove the check for (Win7 Pro and Win10 Pro) Internet Options>Connections tab>LAN Settings "Use automatic configuration script" for all users - to stop using a proxy URL - as an outgoing web security product does NOT uncheck this upon uninstall. If left there, all internet will fail after SW uninstall.

I can't use just GPOs as many remote/vpn users won't process GPOs before connection (using SBL (Startup Before Logon) isn’t an option for other reasons). I tried usin deployment software to (batch script) locally copy a reg fix that clears the AutoConfigURL key upon startup-but this fix doesnt always work, normally it doesn't (copies to startup folder for all users and executes on logon):

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "" /f

I also saw a DefaultConnectionSettings reg key fix - to flip the 9th binary bit to remove the check - but not all systems have this binary entry in registry - and i dont want to introduce a key to Win7/Win10 laptops that don't have it, dont know what it would effect would have on users that don't have it, etc.

What else can I try/reg key can I manipulate to remove the check mark other than Group Policy?
I have a file with 10000 values. I need to search for these values on a Server folder and once found, need to copy the
file to another folder. The values to search for are in one column in a spreadsheet. Values attached. They are PDF's.

How can I accomplish this?
hi, zip file i need to move completely then only i need to copy some files and delete the old txt file and move the new txt file in no 2 code to the destination. so in my below code what i have to add ??


SET /P programName=Enter vehicle program name :

SET ProgramPath=C:\FNASmartServices\REPORTS\BPNO

SET BackupPath=\\ecc9000203\proj\DI_PMTI_SE\PAT\PAT\PATFiles

setlocal EnableDelayedExpansion & time /T
date /T

FOR /R "%ProgramPath%\%programName%\%dateFile%" %%A IN (*.zip) DO (
     COPY "%%~A" "%BackupPath%\%programName%\"

       if(*zip==********************** here code************

dir /a =%BackupPath%\%programName%\ /b > filename1.txt
rem Initialize variables
set OldestDate=999999
set OldestFile=

rem Read each line from list file
for /f "usebackq tokens=*" %%A in ("filename1.txt") do (

    rem Get right 6 characters of file name and arrange in YYMMDD format
    set FileName=%%~nA
    set FileDate=!FileName:~-2!!FileName:~-6,4!

     rem See if this is the oldest file so far, if so save it
    if "!FileDate!" LSS "!OldestDate!" (
        set OldestDate=!FileDate!
        set OldestFile=%%~A
rem Delete the oldest file
echo Deleting oldest file "%OldestFile%"
del "%BackupPath%\%programName%\%OldestFile%" 
del "filename1.txt"

Open in new window

************** what  i need to add if conditon**********
Del "%BackupPath%\PAT BTT Text Files\%programName%\Old\" /Q
echo Old File Removed
Move "%BackupPath%\PAT BTT Text Files\%programName%\New\*.txt" "%BackupPath%\PAT BTT Text Files\%programName%\Old\"

Open in new window

I need to create a small batch file to clean up a directory nightly.
I want to delete all files that are not *.DAT
what is the Syntax for not equal to ?


I have a 2 ink files (price.ini & task.ini) on a windows 2012 shared drive and this was set by my predecessors. I would like to copy these ini files to different two locations on the network PCs.

The current syntax on the login script is
With FS
      '.CopyFile "\\FileSVR-a\MKT\MKTFiles\price.ini", "C:\WINDOWS\", True
      .CopyFile "\\FileSVR-b\MKT\MKTFiles\task.ini", "C:\Program Files\SharkFiles\Shark\", True

Will it be good to do this on a login script or through GPO?

If GPO is best way to do, I would like the file to be copied only once on the PC. If the file is copied , i don’t want the GPO to be applied again.

If so please post me tutorial to set up this.

I can't figure out how to make a lives system for my game and I need to know how.

Here is my code for the lives;

SET lives=5

ECHO  o       Woof!
ECHO /0\   ,###@'
ECHO / \     /   \
ECHO #########################################
ECHO You are walking along the dirt
ECHO road with your backpack and trusty dog Steve.
ECHO You have !lives! lives.

. . .


SET /a lives-=1

ECHO /0\    ,###@                      w   \__,.  \__,.
ECHO / \      /   \                        3--`~  /--,^  /--,^
ECHO #########################################
ECHO You won the fight!
ECHO You now have !lives! lives.
GOTO Scene2

Open in new window

I expected it to output 'You have 5 lives.' in the first section, and 'You now have 4 lives.' in the second part, but instead, I got 'You have !lives! lives and 'You now have !live! lives.'

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.