Text file containing a sequence of commands or program invocations.

learn more… | top users | synonyms (1)

61
votes
9answers
143k views

How to run a batch file without launching a “command window”?

On Windows XP, can I run a batch (.bat or .cmd) file, via a shortcut, without a "black window"?
43
votes
7answers
98k views

How to check if a directory exists in Windows?

I would like to translate this Linux/Bash script to Windows shell: if test -d myDirName; then echo "ok"; else mkdir myDirName; fi It tests if a directory exists, and if it doesn't it creates it.
37
votes
3answers
43k views

How does the Windows RENAME command interpret wildcards?

How does the Windows RENAME (REN) command interpret wildcards? The built in HELP facility is of no help - it doesn't address wildcards at all. The Microsoft technet XP online help isn't much better. ...
20
votes
3answers
50k views

How do I delete directory trees via batch file on Windows 7?

I want to delete the whole content of a specified folder on Windows 7 via batch file. My problem is, that 'del' or 'erase' only deletes the files, not the folders and 'rmdir' or 'rd' always deletes ...
19
votes
4answers
53k views

Remove USB device from command line

I'm constructing a backup script for Windows 7, and the last action I want it to perform is to safely "remove" the USB drive that it is backing up to. I am under the impression that plugging the drive ...
19
votes
5answers
75k views

Properly close (not kill) programs from the command line

What is the proper way to close/exit programs from command line, similar to pressing the "X" close button in the corner of the window? Im trying to close chrome under 3 different versions of windows: ...
18
votes
5answers
133k views

In Windows 7, how to change proxy settings from command line?

How do I change proxy settings from command line in Windows 7? I'm not talking about just the http_proxy. I need to set system-wide proxy settings (the ones in Internet properties setting). How ...
18
votes
4answers
290k views

How can I check a system's current NTP configuration?

I need to verify the current NTP configuration on some Windows systems. Ideally, I'd like to be able to do this via command line instead of navigating through configuration screens. (I'm working on ...
17
votes
1answer
13k views

How to create batch file that delete all the folders named `bin` or `obj` recursively?

I have the need of deleting all bin & obj folders in a folder on my PC. So, I'm thinking of a batch file to do that but I'm not famaliar with batching file in Windows. Please help. [Edit] After ...
15
votes
5answers
16k views

How to delete files from a folder using a list of file names in windows?

i have a folder with 2K+ files in it, i need to delete around 200, i have a txt file with all the file names i need removed ordered in a list, how do i remove the specific files from the folder using ...
14
votes
7answers
29k views

Delete all files from a folder and its sub folders

I want to remove all files from a folder structure, so I'm left with an empty folder structure. Can this be achieved in either batch or VBScript scripting? I have tried a very basic batch command, ...
13
votes
6answers
6k views

How can I open a console application with a given window size?

The application I want to start is MongoDB. If I would start it normally, it looks like this: I don't like the amount of line breaks and I have a lot of screen space, so I would like to utilize ...
12
votes
3answers
24k views

How can I perform a ping every X minutes and check the response time?

I am currently working in a big company and we have serious latency issues. This is happening in a process control system, and is unacceptable (Open a valve sometimes take 2 minutes before command ...
11
votes
7answers
46k views

Is it possible to automatically run a batch file as administrator

I am wondering whether it is possible to automatically open a batch file as admin when you double click on the batch file, because the commands need to be run with administrative rights. Note: I ...
11
votes
3answers
5k views

How to extract a complete list of extension types within a directory?

Within a directory, and recursively within it's sub-directories, meaning every directory within a directory is processed, how do I compile a complete list of unique extensions within the directory? ...
10
votes
3answers
4k views

How can I tell which “explorer.exe” process is the main one?

I have a batch file that changes a few registry files, and then restarts explorer.exe so that they take effect. I'm using the commands taskkill /f /im explorer.exe explorer.exe This of course ...
10
votes
1answer
6k views

how to escape pipe symbol | in bat scripts?

I need to echo commad usage like this in batch script named command.bat command.bat on|off I cant use echo %0 on|off I know I can use echo "%0 on|off" but it puts quotes along Is there any ...
10
votes
2answers
13k views

How can I permanently append an entry into the system's PATH variable, via command line?

What I need to do: Append a folder to the %PATH% environment variable at the SYSTEM level. Make the change permanent. How I need to do it: Using the command prompt, or another method by which ...
9
votes
5answers
7k views

Moving hidden files/folders with the command-line or batch-file

Question Does anyone know of a way to move files and folders that have the hidden, system, or read-only attribute set from the command-line or a batch file? (No, stripping the attributes first is not ...
8
votes
6answers
8k views

Temporarily change directory for single batch-file command

In shell-scripting if I need to run a command from a directory I can us a subshell to ensure I return to the original context: (cd temporary/new/directory ; command) # now I am still in original ...
8
votes
2answers
4k views

Can I set PowerShell as 'default' in Windows 7?

I would like, by default, for PowerShell to be launched instead of Command when, say, running a batch file, or when I "Open Command Window Here", etc. Any suggestions?
8
votes
5answers
33k views

How do I echo a TAB char on a command prompt

On a windows batch file, what is the proper way to echo a TAB? echo A<TAB>B<TAB>C I know I can type the TAB char between entries, but most editors will display it as a sequence of ...
7
votes
4answers
27k views

Sleeping a computer via batch file in Windows 7

I want to make a batch file that will sleep my computer after a period of time. The closest thing I have found is placing it in standby, but seems to work differently than the sleep button on my ...
7
votes
3answers
2k views

Configure a Windows shortcut to prompt for input

I swear I remember some way in Windows-past to set up a desktop shortcut that would prompt for input and pass that into the command it's running. Specifically, I want to run a batch file that takes a ...
6
votes
4answers
8k views

Loading and unloading ISO files in Windows 8

I saw on one site that the new Windows 8 could load ISO images without the help of other programs. Is Windows 8 creating a new drive for every ISO? Or does it have one virtual drive to load all ISOs ...
6
votes
5answers
18k views

How to replace a single character in Windows filenames using a batch file?

I have a Windows Server 2003 server that has a whole bunch of filenames that need renaming. Basically, I just need all - (hyphens) replaced with _ (underscores), no matter where they are in the ...
6
votes
2answers
6k views

Ping every IP address in a text file?

Let´s say I have here a text file with some computer names (each line == 1 name): computerA computerB computerC ... Is it possible to create a batch file that is pinging all of these computers? And ...
6
votes
3answers
6k views

How to sign a Windows batch (.bat) file?

I'm running Windows 7 and when I try to run a batch file, it says, "The publisher could not be verified. Are you sure you want to run this software?" So when I try to sign it with my code signing ...
6
votes
5answers
21k views

Batch file with commands to run as administrator and standard user

I'm trying writing a batch file that needs to run some commands using a local admin account (start/stop a service) and some commands using the logged in user (copy files from the user directory) and ...
6
votes
3answers
8k views

What does the percent sign (% and %%) in a batch file argument mean?

I think I'm missing something because I can't seem to find what this means. Example: for /D %%A in (*) do "\7za.exe" u -t7z -m9=LZMA2 "%%A.7z" "%%A" That line was supposed to use a command line ...
6
votes
1answer
98 views

something strange about Win-XP's command shell

I wrote the following command in windows XP's command shell and something strange happened: C:\Folder1> copy sample.txt : Because of my typing mistake, I wrote ":" instead of "D:" ... but it ...
5
votes
3answers
2k views

CMD - Why “start winword” works but just “winword” doesn't

Assume Microsoft Office is installed. Consider the following batch file: REM the following line successfully launches Microsoft Word start winword REM none of the following commands work to launch ...
5
votes
2answers
22k views

Windows batch file if else usage

Sorry I am new to this stuff. I'd like to run in a certain sequence the same bat file with different parameters. I wrote a very simple batch file: @echo off REM Note: to see all command line usage ...
5
votes
1answer
9k views

Batch convert *.avi files using ffmpeg

I am trying to convert 20+ .avi files in a batch using ffmpeg. I've got the following @echo off. for file in *.avi do ffmpeg -i "$file" -s 640x480 -vcodec msmpeg4v2 "'basename "$file" ...
5
votes
3answers
304 views

Start up computer in the morning

We are requested by management to shutdown all systems when we leave in the afternoon, any system left on is consequently shutdown by the cleaner (pulls the powercord i guess). What I hate though is ...
5
votes
1answer
2k views

Wildcard Services restart

Currently, we have setup a .BAT file which lists all services to start / stop them eg. SC start SERVICE SC start SERVICE SC stop SERVICE SC stop SERVICE We add new services all the time and the ...
5
votes
3answers
4k views

Windows 7 batch file: Why are these IF blocks keeping me from assigning variables to a value?

Here's the broken batch file: @echo off if prod==prod ( if xps==xps ( set i1=prodxpsi1 set i2=prodxpsi2 set e1=prodxpse1 set e2=prodxpse2 ) else ( set ...
5
votes
2answers
3k views

Find all MKV files and remove all subtitles

I'm currently looking at a Windows program called mkvmerge. I would like to create a batch file to find all MKV files recursively from a specified path, and remove all subtitles from the MKV files ...
5
votes
1answer
4k views

Remove registry keys using reg.exe in a batch script

I've written this little batch script to help me auto-clean the registries of 300+ identical PC's of some very specific registry keys. It works right up to the point of passing the key variable to ...
5
votes
2answers
2k views

Selectively deleting system scheduled tasks

Windows 7 box has a list of scheduled tasks - > Default Windows tasks + Certain custom tasks that all start with a certain string. Previous code deleted all tasks with the command: schtasks /Delete ...
5
votes
2answers
1k views

Disable close button on DOS program in Windows 7

At my company we have stores that run some old DOS software. Before Windows 7 you could run these programs in full-screen and now you cannot. I know there are work-arounds to get in full-screen ...
5
votes
1answer
1k views

Environment variable for volume names in Windows?

I'm trying to write a batch file that will look at the volume label of the current drive and report if it's not equivalent to a certain string. Is there a default variable in the shell for this? Can ...
5
votes
3answers
5k views

Starting services in batch file on windows 7

I have a fairly simple batch file which does just one thing - "net start myservice". This batch file gets shortcut-ed in a program group by installer so that users can simply click on the icon and get ...
5
votes
2answers
7k views

How do I use a " (quote) as a FOR /F delimiter in CMD.exe on Windows 7

I want to have a .bat file get a list of all of the *.XML files in a Visual Studio project What I tried so far is to first use an old version of GREP: SET TempName=%temp%\TEMP%RANDOM%.bat ...
5
votes
3answers
268 views

Arrange JPG images based on JPG compression/quality

I have been looking for a way to arrange JPG images based on the quality/compression level of the images. I want to do this so that I could select only those images which has less compression (let’s ...
5
votes
1answer
922 views

How can I launch batch files from another batch file while piping their output and retaining the current working directory?

I have a batch file which runs as a scheduled task. For the sake of example lets call it alltasks.bat. It looks like the following: @ECHO OFF clearwebtemp.bat > clearwebtemp_out.txt ...
5
votes
3answers
3k views

Creating a folder from first 5 characters of filename in a batch file

Here's what I have: C:\test\12345-test1.txt C:\test\23456-test2.txt C:\test\44444-test3.doc I would like to have the script read the first 5 digits from the file, create a folder with those digits, ...
5
votes
1answer
96 views

Why do my .BAT files on Windows 7 not PAUSE properly?

I've been playing around with writing batch files on my computer for some time, and I am confused about why PAUSE doesn't work like I thought(maybe I'm just doing it wrong idk, just really confused). ...
4
votes
1answer
3k views

Windows batch file reference to own directory

Suppose you have C:\foo\foo.bat which needs to refer to C:\foo\foo.txt. It may be run from a different directory, but needs to get foo.txt from its own directory, not the current directory. Obviously ...
4
votes
3answers
1k views

Why does my batch script not run all lines?

I want to create a batch script that will run axis wsdl2java.bat for multiple WSDLs. When I create a batch script with just this code: wsdl2java.bat wsdl2java.bat it would run wsdl2java.bat only ...