Text file containing a sequence of commands or program invocations that does not need user intervention.

learn more… | top users | synonyms (1)

50
votes
9answers
114k 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"?
38
votes
7answers
80k 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.
33
votes
2answers
29k 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. ...
14
votes
5answers
106k 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 ...
14
votes
4answers
34k 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 ...
14
votes
1answer
10k 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 ...
13
votes
6answers
3k 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 ...
13
votes
3answers
200k 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 (especially since ...
13
votes
5answers
32k 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: ...
12
votes
4answers
10k 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 ...
10
votes
3answers
3k 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
11k 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
1answer
4k views

Why unload variables in Windows batch files

Is it considered necessary or good practice to unload variables used in Windows batch files? For example in the following code, is the set myFolder= at the end necessary? @echo off set ...
9
votes
5answers
6k 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
1answer
5k 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 ...
8
votes
2answers
3k 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?
7
votes
4answers
24k 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
3k 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? ...
6
votes
5answers
10k views

Delete all Files from Folder and Sub Folders

I'm wanting 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 VBS scripting? I have tried a very basic batch command but ...
6
votes
4answers
7k 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
6answers
6k 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 ...
6
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
5answers
26k 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 ...
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
1k 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
5answers
14k 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 ...
5
votes
2answers
3k views

Ping every ip in a textfile?

Let´s say I have here a textfile 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 ...
5
votes
3answers
297 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
4answers
7k 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 ...
5
votes
2answers
15k 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
6k 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
4answers
3k views

Using Batch File to Transfer files to flash drive when connected [duplicate]

I have about 1,000 flash drives that I need to move a set of files onto. I'm looking for a way to reduce the amount of time this will take. Thoughts: Attach task to the event of connecting flash ...
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
1answer
3k 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
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
5k 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
249 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
784 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
2k 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
61 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
2k 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
5k 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 ...
4
votes
3answers
905 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 ...
4
votes
1answer
2k views

How can I retrieve input from the user in a .bat file?

I'm the using the command dir /AD /B "\\computerName\users\" >> user_export.log Is it possible to create a batch file that asks the user to enter the Computer Name and then when the end user ...
4
votes
4answers
4k views

Run a batch file before user logs into Windows 2003 R2?

I have an Amazon EC2 machine (Windows Server 2003 R2) where I want to run a script (.bat file) when the Windows Server 2003 R2 machine boots up. This need to run BEFORE any user logs in. Ideally I'd ...
4
votes
2answers
5k views

how can I make my .bat file continue after an error

I have a .bat file in windows that does three things cmd1 arg1 arg2 cmd2 arg3 cmd3 arg4 arg5 arg6 Sometimes cmd1 can fail and that's fine, I would like to carry on and execute cmd2 and cmd3. But ...
4
votes
2answers
1k 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 ...
4
votes
2answers
17k views

batch script that grants admin rights and goes through all files and folders

I have this, pretty sure its a little harsh but does the job, gives me all the rights to the files and folders on a drive when run on a drive, now I need help getting it to go into sub directories, so ...
4
votes
1answer
5k views

Get current folder name instead of current path in windows batch file [duplicate]

Possible Duplicate: Get current folder name by a DOS command? In my batch file, I have, SET currentFolder=%CD% echo "%currentFolder%" Prints the whole directory path. C:\www\scritps\ ...