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

This is my command line:
@echo off
FOR %%f IN (P*) DO type %%f >> combiness.txt & echo. >> combiness.txt

Open in new window

To put all files starting with P in a combiness.txt file, it worked on my old computer but i recently got a new one and its not working like I had hoped.
Free Tool: Port Scanner
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

I have a user who puts the date he wants me to change the to reflect the update in the file name.

Example:  BMS Update 7.21.2017.xlsx

Is there a way to capture this Date in the file name so I can use it in my batch routine?  Maybe like store it in a set variable so I can use it in my batch file.       Set FileDate=FileDate

I cant use file modify date because the modify date and the date in the file name are different.
Hi Experts,

I have this script tested and works as expected.  script checks the disks attached to server and checks the  drive label  of the disks and create a .txt file with the drive letter name ( such as "D drive.txt")  scripts is copied to  each server already and locally run.

For an example, if four disk found as D, E,Y,S on a local server, after running the script,  when I  go into each disk, I should have a .txt file saved in there as D drive.txt, E drive.txt , Y drive.txt and S drive.txt

batch script will be used on  mixture Windows OS versions. ( 2003 to 2012)

Issue: it works fine when script is run locally but when needed to run using PSexec, it produces different issues  even though script is on the local server and all PSexec should do is executing the script with remotely instead of logging into the each server. I have read on forums that vmic is not very friendly with PSExec, is there way to eliminate wmic from the script? here is forum talks about the issues it causes:

thanks in Advance

I want to reboot my client computer.
I want to give him time like 1 hour
but I want him to have a option he can restart before 1 hr whenever he wants.
I have created a Powershell Script and a Batch file.  I have placed the batch file in the startup directory of the machine.  It appears to run as I see the command prompt window on the screen with the message "Press any Key to continue".  If I press any key the command prompt goes away and the app I want removed (XBox) is still on the Tiles Page and works.   If I double click the script once logged in as any user it runs ... presents the same cmd prompt window with press any key to continue ... and removes the app.

I am hoping to fix two issues:

1) Remove the need to press any key to continue.  I want it to be invisible to the end users.

2) Get the script to delete the XBox app without having to wait until logged in and then manually clicking the batch file.

PowerShell.exe -ExecutionPolicy Bypass -Command "C:\scripts\RemoveW10Apps.ps1"

PS Script:
Get-AppxPackage Microsoft.XboxApp | Remove-AppxPackage

Thanks for any advice.
This is about the Acronis Backup & Recovery 11. We found that one of the service - Acronis Managed Machine service (mms) sometimes shows "stopping" while kicks start the scheduled backup job. When this service in this state, the only way we can do is to system reboot the server so as the service will be back to normal started state. We did use process explorer to "kill" the mms, however, we still can't manually start the backup job.

Out of no way, we are using the task scheduler to schedule to stop and start 5 Acronis services. Basically are those net stop/net start commands with 30 seconds interval as attached. The sequences are, net stop all the services in this orderly - Acronis Managed Machine service > Acronis Remote Agent > Acronis removable storage management > Acronis Scheduler2 > Acronis VSS Provider; and then net start same services in reverse order.

However, still, the Acronis Managed Machine service shows "stopping" upon the schedule restart. Is there a way that stop this service forcibly? As long as this service is stop, and then re-start shouldn't be a problem.

Every month I have to go through several text files after paying bills online to send to the CFO to show all the bills that have been paid. I have tried to get him to accept a print of confirmation page but instead he wants it in the format of file 2 below (ee-online-pmts-result.txt). So I copy the results from the web page, past it to a text file and then clean it up removing all the "junk" not needed. As such is there a way I can read the first text file (ee-online-pmts.txt) and then have a list of variables to parse that if found would be removed in such a way that the result will be what the 2nd text file looks like? For instance if  "Print this activity" and two carriage returns (enter, enter) are found it will remove it? Thanks!
Hello folks,
I need to create a shortcut by using a script batch or PS1 or vbs, I have found this for now but it will not give me a ie

echo start > "%userprofile%\desktop\Google.cmd"

does anybody has a better solution ?

I'm changing the DNS Servers on our Environment to new IPs. i found a batch script which worked perfectly on the Servers that have one connection only but for the servers that have two it didn't worked as it some time change the DNS for the correct one and some time no.

how i can modify it to change the DNS for the network interface that have the old IPs or that Connected to the Domain.

below is the script & I want it as batch to deploy it by SCCM

@echo off
set dnsserver=
set dnsserver2=

for /f "tokens=1,2,3*" %%i in ('netsh interface show interface') do (
 if %%i EQU Enabled (
 rem echo change "%%l" : %dnsserver%
 netsh interface ipv4 set dnsserver name="%%l" static %dnsserver% both
 netsh interface ipv4 add dnsserver name="%%l" %dnsserver2% index=2


Open in new window

I have created the following batch script
For /f %%a in (Clients.txt) do (
 psexec \\%%a cmd /c reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v version>>report2.csv
 IF %ERRORLEVEL% EQU 0 @echo %%a>>report.csv

Open in new window

However my report shows, version information on top and then PC name at the bottom a bit messy ... what do you guys think i should change in order to make the result, two columns one for PC NAME and next column VERSION. or any better suggestions? [including powershell ]?

Thanks for looking
[Webinar] How Hackers Steal Your Credentials
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT


I am wondering if there is a way to automate (through script) the steps on this article?  
Thank you in advance!
I'm trying to automate the post-installation actions for a Windows update patch, but running into trouble when it comes to elevating privileges.

Ideally what I want to do, is use a batch file to run an elevated command, then call a PS script to run a separate elevated command, with a minimum of user input.

Is this possible, and if so, what is the best way to implement it?
I need to write a batch file to substitute tab with white space
I don't know whether this is possible or not but here goes ...

I have a Windows 10 Home laptop and and various Windows 10 Pro boxen.  I'd like to share files between them without using USB sticks or using the HomeGroup feature of Windows.  (I do want the Windows 10 boxen to talk to my [new and upgraded] Linux Samba box but that is a future project).

I've got sharing (over Ethernet) working between the Laptop and one Pro box and I presume I can disable it through the GUI.  I'm only sharing one folder that of Documents on both machines.  BUT I would like an easy way to disable and enable it, hopefully through the use of CLI commands and a batch file.  Is this possible and if so how?
Thanks in advance
My code is posted below.  There 3 IF  ELSE statements to check all possible conditions.  I don't understand all the More? being inserted; or the ) was unexpected at this time.  This is the last hold up I can't correct.

Please help

@echo off
rem setlocal EnableExtensions EnableDelayedExpansion
set SrcFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfiles
set DstFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfilesCustomSubmissions
for %a in ("%SrcFolder%\*.txt") do (
More?   (for /f "usebackq delims=" %h in ("%a") do (
More? echo.%h
More? (
More?  if "%h" equ "[**]details==>>countries||==||" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More?  else if "%h" equ "[**]details==>>countries||==||USA" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More?  else if "%h" equ "[**]details==>>countries||==||USA, Canada" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More? )
More? ))>"%DstFolder%\%~nxa"
) was unexpected at this time.

echo DONE
Hi, please can someone assist with this batch file.

I am trying to get the CMD window to close after the batch file has run, please can someone advise where I am going wrong.

SET year=%DATE:~-4%

SET month=%DATE:~-10,-8%
set month=%month: =0%

SET day=%DATE:~-7,-5%
set day=%day: =0%

SET hour=%time:~0,2%
set hour=%hour: =0%

SET minute=%time:~3,2%
set minute=%minute: =0%

SET second=%time:~6,2%
set second=%second: =0%

SET datetimeStamp=%year%%month%%day%-%hour%%minute%%second%

SET CMD="D:\Program Files\SunGard\Apex\bin\Windows 64-bit\Apex.exe" -logMessages -showMessages -verbose -logFileName %userprofile%\AppData\Local\SunGard\Apex\Logs\SunGardApex-%CIBC_ENV%-%COMPUTERNAME%-%USERNAME%-%datetimeStamp%.log

SET START_PATH="D:\Program Files\SunGard\Apex\bin\Windows 64-bit"

IF NOT EXIST %userprofile%\AppData\Local\SunGard\Apex\Logs MKDIR %userprofile%\AppData\Local\SunGard\Apex\Logs




Open in new window

Hi all...

I've tried finding what I need but most solutions offer various entries and switches on a vbs script or batch file.

I need to delete one single registry key if it is present. The key is as an example:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\DATALOSS1000

How can I accomplish this, and run it remotely on approximately 300 systems?

Batch file preferred...

Thanks in advance...
I need to copy files from the source to destination and only copy the files with the current date :  I can create copy etc, but it is grabbing all the files not just the current date.  I don't know what I am missing.

@ECHO Collect Todays WSA Logs.......


For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set currentDate=%%a-%%b-%%c)

For /f "tokens=1-3 delims=/: " %%a in ('time /t') do (set currentTime=%%a%%b%%c)

echo %currentDate%-%currentTime%
set todaysLogs=%currentDate%--%currentTime%

mkdir d:\Logs\%todaysLogs%\WSA

xcopy /i /e "\\SOURCE\c$\WINDOWS\temp\*.TMP" "D:\Logs\%todaysLogs%\WSA" %date:~4,2%-%date:~7,2%-

batch script help with exit when finds a specific error( e.g:

Open in new window

) ,exit means close the process
On Demand Webinar: Networking for the Cloud Era
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Hello All, I have this .bat for change expiration date of users in a .csv file, but I decide which date I want to put.

Now, How can I change that the date will to NEVER?

[b]@echo off

:: *** csv-File with the name, first name, and user name:
set UserFile=\\Srv_\publico\DATOS\Procedimiento\Procedimientos\prorrogarUsuario\prorroga.csv

:: *** Distinguished Name of the container to add the new user to:
set UsersDN=OU=Usuarios,OU=UsuariosCM,OU=CM,DC=D,DC=domain,DC=com

for /f "tokens=1-4 delims=," %%a in ('type "%UserFile%"') do (
  set Userp=%%a
  set Date=%%b
  call :process
goto :leave

set USER=%Userp%

echo Prorrogando usuario
echo Username: %USER% date: %Date%

:: ***echo Hit ^<ctrl-c^> to stop, any other key to create the user.
:: ***pause >NUL

:: *** Test mode: Remove the "ECHO" in front of the following line to run the script for real:
net user %USER% /expires:%Date% /DOMAIN


Open in new window

Can u help me?
How do I check this. Have already written a command in SQL SERVER JOB [Test_Job] and executing the job in Sql Server, **Have disable the Informatica service through Informatica Admin panel**, when I execute this job I don't know why It is still running successfully and cannot generate a failure mail.

This is the command which I have put in a job.

    DECLARE @result int
    EXEC @result = xp_cmdshell "D:\Informatica\Informatica_961_HotFix2_Installation\server\bin\infacmd ping -dg HERHRETEST:1000"
    IF (@result <> 0)
        RAISERROR (50001, -1, -1)

Please help at the earliest
When ping is negative Stop Xsoft.exe with this command :
 NET STOP "Xsoft (managed by AlwaysUpService)"

Open in new window

Wait 1 min. and try again,if ping is positive then start Xsoft.exe with this command: :
 NET START "Xsoft (managed by AlwaysUpService)"

Open in new window

E.g. negative answer:

Pinging with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

Open in new window

E.g. positive answer:

Pinging with 32 bytes of data:
Reply from bytes=32 time=16ms TTL=58
Reply from bytes=32 time=15ms TTL=58
Reply from bytes=32 time=14ms TTL=58
Reply from bytes=32 time=15ms TTL=58

Ping statistics for
    Packets: Sent = 4, Received = 4, Lost = 0 (0%  loss),
Approximate round trip times in milli-seconds:
    Minimum = 14ms, Maximum = 16ms, Average = 15ms

Open in new window

If ping is positive all the time then let it run continuously
I need a batch command to stop the process and exit immediately when it finds this error:
connection error

Open in new window

the batch works with a certain tool and these are some benchmarks if they help something
The script I own closes the process in these situations and I want someone to help me add a new situation

:: Controll stopping
:: (1=enable,0=disable;)

Open in new window

:: Error exit codes

Open in new window


1'st exit situation:
:: Check if the file exists
IF NOT EXIST "%filep%" (
	ECHO File "%filep%" was not found. Assuming we ran out.
	ECHO We did not find.

Open in new window

Another exit situation:

) ELSE (
	:: tool did not run ok. No ideea why. The multitude of checks should have
	:: prevented this.
	ECHO %tool% exited with non-zero exit code. No ideea why. Contact dev.

Open in new window

The 3'rd situation:

:: Call command

:: Check if we ran ok
	:: Check if we found mamammia
	FIND "Discovered mamammia" "%tooloutfile%" >NUL 2>&1 && (
		ECHO mamammia.

Open in new window

I want to add new exit,so when finds this error EXIT:
connection error

Open in new window

I have a file with a £ sign in it.  When I FTP it to a mainframe dataset there is an extra B before it.  How do I get rid of the B?
This is my batch file

open server
user aa bb
quote site xlate=DSUKEAT
put C:\DS_SDI\SIDB\Uploads\P3EP21.txt 'dataset'

It is called from this batch file.
ftp -n -s:C:\DS_SDI\SIDB\Uploads\P3EP21ftpMF.bat > C:\DS_SDI\SIDB\Uploads\P3EP21ftpMF.out

Here is the results file with server names, IDs and passwords changed.

ftp> Connected to server
open server
220-FTPD1 IBM FTP CS V2R1 at TCPP2, 10:42:31 on 2017-06-30.
220-**    Welcome to server FTP Server
220 Connection will close if idle for more than 15 minutes.
ftp> user aa bb
331 Send password please.
230-*** User Logon to qq DSP2 FTP Successful
230-*** FTP Queries: qq
230 P3EP21 is logged on.  Working directory is "P3EP21.".
ftp> quote site xlate=DSUKEAT
200 SITE command was accepted
ftp> put C:\DS_SDI\SIDB\Uploads\P3EP21.txt 'test'
200 Port request OK.
125 Storing data set test
226-Statistics have been updated for the PDS member that was transferred
226 Transfer completed successfully.
ftp: 411 bytes sent in Seconds Kbytes/sec.
ftp> 0.480.85bye
221 Quit command received. Goodbye.
i need a batch file to create this path: C:\Windows\winwin123
this path already exist: C:\Windows\  but the folder called  ''winwin123 '' must be created ,afetr is created i want to go there: C:\Windows\winwin123

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.