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 am looking for a .bat to .exe converter for Windows 10
Why Diversity in Tech Matters
LVL 19
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.


I have an ALL Staff Universal security group, which we use for sending email for ALL Staff.

Within this ALL Staff Universal security group, there are other departmental mail groups added as well. I would like to have the list of all users who are member of this ALL Staff Universal security group

Is there a way of exporting all the members to a notepad or excel.

Any help will be great.
Hello experts,

I have a file with multiple lines.

I am looking for an script or a regular expression to retain lines which start with the following string: 2019-11-21 and contains the following string : “loading file”

Thank you for your help.
Hi, I am trying to promote a Windows 2016 server (SERVER2) to a domain controller in MYDOMAIN from a windows server that is not part of that same domain. Then clean up the metadata left over from SERVER1 that is never coming back online. Then run dcdiag health checks against SERVER2 (now a domain controller in MYDOMAIN) and other already exsisting domain controllers in that same domain. I am not looking to build a script that needs no input. Someone will be providing account names and password for the admin account (member of enterprise administrators) used to authenticate to MYDOMAIN.

And thank you for any and all help from anyone offering, regardless if your suggestion is used or not. I appreciate it very much.

I can use powershell to load ADDS and promote the server I am logged onto to a domain controller, I am just hung up on how to do it remotely. There aren't any issues with running ntdsutil from a standalone server against domain controllers in MYDOAMIN, is there?
I have a VERY small batch file which was created a couple of years ago by an expert here on EE.  Now I need two very small and simple changes made to it (I am not a programmer, obviously). I just tried posting it to Fiverr, where I have an account, but their list-a-job is miserably lacking for such a thing.

SO...would any expert care to handle this for me? I have a strong feeling that this is a 5-minute or less task for anyone who knows .bat files.

I need to make some registry changes using the below.  When I copy and paste the lines in a  CMD window run by administrator, I am getting syntax error.  

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 0 /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask / t REG_DWORD /d 3 /f

Please advise.  

I would like to create a powershell script or batch file script that will run multiple software  one after on multiple  remote computers  and show progress bar while installing and creating log file.
How can I do that bt scripting
Hello Team
I like to have a batch  cmd file or powershell script to  copy folders (documents,downloads,desktop,favorites) from user that has old computer  with old computer name to user  that will have new computer  with another computer name  both computers have different computer names and connected to same network as I would like to run this  script on  new computer of user so  it has to ask for computer name so I write old computer name of user and then ask about user folder so I select user profile from c users folder and after it copies documents ,downloads,desktop ,favorites from old computer of user to new computer of the user as i would like to acheive that in powershell and batch cmd  that shows progress bar while copying and log file
I am trying to run .vbs script who reads data from Excel. It works fine when I run it from command line but it does not work if I run it from Task Scheduler, but if I run it as Administrators  from Task scheduler it works. But the I can only save the task as "Run only when user is logged on"

If I run the commands below the first one opens a notepad text file in a maximized notepad window. The second one opens the same file but the notepad window is minimized.
So I am wondering two things.

1. Is there a way to open the notepad window so that it is half or fractionally open? Like 1/2 the normal size.
2. Is there a way to specify the location of the notepad window when it initially opens? Like left of center?
    I ask this because I will open a two notepad windows and do not want them to all be in the same location/coords. I would prefer
    that the last window open is displayed slightly to the right of the first notepad text file displayed.

1. C:\cmd.exe /c start /max notepad.exe c:\mySampleFile.txt

1. C:\cmd.exe /c start /min notepad.exe c:\mySampleFile.txt
C++ 11 Fundamentals
LVL 19
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hi Experts,

I've a batch script for pinging multipal ip's, now i want convert this batch script to C# Windows Forms App (.NET Framework) & run ping with start button.

Please Suggest ?
I want to install from command line (script), and MSIE add-on, which is a cab file stored on internal web server.
The cab contains two files:

The inf contains, that:

I see on Internet, different solutions, but nothing works.
rundll32.exe advpack.dll,....
pkgmgr ...
I've tried to copy the two files, on "C:\Windows\Downloaded Program Files", to register the ocx with the regsvr32.exe command.
After that, the add-in is in the add-ins MSIE list, but is disabled.
I don't know how to enable it with command line?

My purpose is to automate the add-in installation, directly without GPO (I have another tool to teledistribute, an automate some actions).

Thank you for your help.

I need a custom script or batch written to check for the existence of two daily files that should exist for the next day. More specifically, we have a scheduler system that should be exporting a proprietary file for the next day. If this file does not get created then someone needs to be alerted prior to midnight when that file would need to be used. The scheduler is creating two files for each day so we would need to check for both. The format of the files is MEGA%MM%%DD% and BLAZE%MM%%DD%, where %MM% is the 2-digit month and %DD% is the 2-digit day of the month. Example of files: MEGA0913 and BLAZE0913. Neither file has a file extension so Windows just sees them as a type 'file'. I plan on using task scheduler to check for both files at 9pm of the day before. So on the 13th, the script would run at 9pm and be looking for MEGA0914 and BLAZE0914. Both files reside in the same folder. If either of the files is missing then the script needs to send an email, using BLAT or similar to alert an email address as to which file(s) are missing.
I am trying to enable TCP/IP and Named Pipes using the following command. But I have encountered the error:--

WMIC /NAMESPACE:\\root\Microsoft\SqlServer\ComputerManagement10 PATH ServerNetworkProtocol Where ProtocolName=’Np’ CALL SetEnable

Please see the attachment.

I have created batch job to copy a file to UNC path, which is mapped to my computer. The batch job run from task scheduler but the file doesn't transfer to UNC path. But if I run command manually is successfully copy files. I have tried both batch below:
  @echo off
pushd c:\xxx\zzzz\yyyyyy\
COPY * Q:\test\--(note:this is the map drive letter for unc path)
Sleep 5
@echo off
cd c:\xxx\zzzz\yyyyyy\
move * Q:\test\--(note:this is the map drive letter for unc path)
sleep 5
del *

Action Started
Task Scheduler launched action "C:\Windows\SYSTEM32\cmd.exe" in

instance "{90e9b280-15df-4a79-9ec1-6bef9a621423}" of task


Action completed
Task Scheduler successfully completed task "\xxxxxx" , instance

"{90e9b280-15df-4a79-9ec1-6bef9a621423}" , action "C:\Windows

\SYSTEM32\cmd.exe" with return code 0.
Dear All

               How do i remove reg key without asking yes or no ? i have put /f at the back of the command but doesnt look like correct, i want to create a login bat to GPO, any help would be appreicated

Hi all,

First of all I'm don't know a lot about scripting and that's the reason I'm here requesting some assistance. So here I go:

We do have a GPO that runs a logon script (batch file that then runs a PS1). The whole purpose is to create shortcuts on the folder redirected desktop of such users (on a Citrix server environment) if they belong to those groups.
The problem we are facing is that sometimes the shortcut will not get created. Based on troubleshooting it seems this script is not the most efficient way to accomplish this task and basically the reason why it doesn't get created is because it times-out. Every day we get calls that the shortcut was not created and most of the time running a GPUPDATE or login the user off/on corrects the problem.

So here I'm asking is a better way to accomplish this task? Please let me know.

REM ---------------
REM -Version Check-
REM ---------------
echo f |XCOPY "\\company-file1\apps\ClientApp\CA\rtclient.exe" "%appdata%\Clientapp\CA\caclient.exe" /D /y /f /e
echo f |XCOPY "\\company-file1\apps\ClientApp\CA\ClientAppUpgradeFix.bat" "%appdata%\ClientApp\CA\ClientAppUpgradeFix.bat" /D /y /f /e
REM -------------------
REM -End Version Check-
REM -------------------

Powershell.exe -executionpolicy remotesigned -file \\company.corp\SysVol\company.corp\Policies\{F144FEB7-BEEA-49C8-B421-3A0F1A089776}\User\Scripts\Logon\UserValidate-Profile.ps1

It then runs that PS1 powershell

Import-Module ActiveDirectory
I had this question after viewing batch file to add map driver for network location and ask for credential.

I have two "DC" and now I'm trying to create a batch or shortcut to DC2  to be map to other folders.
net.exe use X: \\APPS \PCC storage * /user:DC2\myname /persistent:no
Is this fine
or another below statement..

@echo off
if Not exist y:\ (

echo Please enter User ID:
set /p USERID=

echo Please enter your Password:
set /p PASSWORD=

cmdkey.exe /add:APPS.US /user:dc2\myname /pass:%PASSWORD%

net use O: "\\APPS\PC1 storage" /persistent:YES
I have few OS commands which I need to run only through ADMINISTRATOR's CMD console
please advice how to call such batch script

example :TEST.BAT
how to make sure below  script called from admin cmd console

echo " Hello"

Become a Microsoft Certified Solutions Expert
LVL 19
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Dear All

             i have made below bat file to client desktop, and found that 1 computer showing the wrong ip address after click on the bat file, the ip show the old DC & DNS server, any idea what goes wrong ? any idea to get it fix and showing the real computer ip address ?

@echo off
REM myip.bat
REM script to return just the IP address of the current host.
REM Works on Windows 2000 / Windows XP
FOR /F "usebackq tokens=2 delims= " %%i in (`nslookup %computername%`) do set myip=%%i
Echo IP Finder
ECHO -----------------------------------

ECHO My IP Address Is: %MYIP%
ECHO My Computer Name Is: %COMPUTERNAME% 
ECHO -----------------------------------

Open in new window

I am wondering if it is possible to change a line in an ini file using a batch script to a specific directory on a drive
when a batch-file is executed in cmd. I want to make sure that exactly one parameter has been passed.
How can I do this?
I want to install the SCCM agent on a list of computers listed in the text file  c:\temp\list.txt from my computer using the command below.

PSEXEC @”:C\temp\list.txt” –d –h –s –c  “C:\temp\sccmclient.bat”

The sccmclient.bat should do the following
Run this command

The ccmsetup.exe is in a shared folder on \\fileserver1\share1\ccmsetup.exe

I want to run this command with elevated privileges so want to include username and password in the above PSEXEC command.
I tried it with quotes, without quotes but looks simple but this thing does not work.
Appreciate some help
I am trying to run procedure in cshtml and want to run one procedure automatically.  Dont want to use windows service or batch file as it is not really working.

i am using something like this in the batch file which runs every hour
start "<C:\Program Files\Internet Explorer\iexplore.exe>" 

at one point it says completed successfully but it is not doing anything ie. not running the downloadfeatures method. Can you please help? Any automated tool i need to use to run this cshtml file?
I have a scheduled task that runs a batch file.  The batch file has several lines where I do a "git pull" command from a specific Git repository.  The Windows server where this runs has already been configured with proxy settings so that when you run "git pull" or any "git" command, it will properly connect to the required repository and run the command.  I have figured out that this schedule task and batch file will run just fine when a user is logged on.  But if I log out of the server, the schedule task start, but the "git pull" command gets stuck.  It's almost like it's can't connect and then the rest of the batch file will not run.  What should I do to ensure the "git" commands run fine even when a user is not logged in?

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.