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

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
Free Tool: Path Explorer
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.

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
Enroll in July's Course of the Month
Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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
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 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
Hi all,

I am currently in the process of putting a logon script together in order to map network drives for users. This should be easy, but the drive mappings will be connecting to storage on another domain - without any trust relationship between the domains.

There is a legitimate reason for the trust not being there, if it was this would be much easier.

Each user has their own logon script (%username%.bat), which has a list of drive mappings using the 'net use...' commands to map to the storage on the second domain. Within the second domain, they also have another AD account (exactly the same username format) with the correct permission to the storage.

My initial idea was to place a script called 'runas.bat' within the 'NETLOGON' area of the domain they're logging into, with a one-liner of runas /user:<secondDomain>\%username% "%username%.bat" - hoping that this would run for each user, ask for their credentials to the second domain, and then run the required %username%.bat for that user to map the drives.

The problem... the 'runas' script will not run against a UNC path, so the script also defaults to 'system32' and the %username%.bat scripts cannot be found.

I have seen suggestions of temporarily mapping a drive letter within the 'runas.bat' script, but this would get messy.

The domain they're currently logging into will soon go, they're in the process of migrating all users, business data, and applications across to the new domain. The data …
I have a folder which contains several thousand .pdf files.
I would like a program which can
1. find a file in a folder based on the file name
2. copy that file
3. paste that file to another folder

All these "source" files will be in .pdf format in a single folder.
I need it to do this in a "batch" format where you can specify several file names in a given folder and copy all those specified files over to a different folder.
I have used Excel to generate a list of the file names that I want to copy/paste.

Thanks in advance for any insight on how to accomplish this!
How to automatically stop the exe process when it can not run? i start exe process i check ALL ACTIVE PROCESSES and I do not see him anywhere,then how can I stop it immediately
Hi Experts
I need a batch file to change folder permissions and sub folders to the following
remove every users permissions except the administrator and the administrator only have the read only option
My source folder is a build output folder where in multiple folders will get created. I would like to pick the latest folder to the destination folder using robocopy or any other method. how can I do it ?
Who can help me create a script to monitor and stop automatically MySpecific.exe process but only when CPU activity is idle for a given period of time?
e.g: I run MyTool.exe ok ? how can i monitor the CPU activity?and when MyTool.exe is idle for a given period of time (lets say 1-2 min) then the created script must stop  MyTool.exe process,is possible that?can anyone help me?
thank you!
Get HTML5 Certified
Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

I'd like to be able to run a weekly script on my domain workstations (Windows 7 and windows 10) that will populate a CSV log with username, computername and last successful windows update.

What I currently have is this:
SET filename="C:\Windows\System32\catroot2\dberr.txt"
FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
echo %username%,%computername%,%filedatetime%>>....hotfixes.CSV

This kinda works, but doesn't tell me an update failed. Or if updates were downloaded but not installed.

Is there a better way to achieve what I'm looking for?
Hello All,

I have been trying to get some assistance and received various inputs in one of the earlier question to run a .bat file on multiple servers.
Below is the steps I want to execute:

a. We have 109 server (Windows 2012 Server)
b. There is a batch file in D drive with same name and location on all 109 servers
c. I want to run that particular batch file on all servers in one go
Usually when I login to my session using credentials and launch the batch file, multiple command prompt windows start loading. When I used PSexec script it works for individual machine but there too I had a challenge... If my PC gets locked the batch file fails and stops.

All I am looking here is to run that particular batch file on all servers and if I login to my session I should see it has started. I want the batch file to run under by login session. Please help as this is very critical to be completed ASAP.

Let me know if any more information required.

I would like a DOS batch script that checks the status of a running task, however if the task is running more than 10mins to complete, the task should stop running and report that the task has been running more than 10mins
Please help me with a command or script give a few folders read and write permissions on remote machines using ICACLS in windows 2k12 servers.
I need to write a script to have a PC dump certain log files.  I have to use DameWare to get to these PC's, so i am remoted in.  After the files are dumped into (preferably) a .zip file, i would be set.  However, the dates change daily, as does the number of files.  Some days here may be 3 logs, some there may be 9 (or more).  I need help writing this script, as well as t-shooting the firewall problem.

Thoughts ..........?
Greeting Experts,

I need a basic batch file where I can move list of records (from one directory to another) that are older than 10 min based on the last write time. I need to have this bat file kick off every 10 min once it starts... Is there somebody that can help me with this request...

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.