batch

How to get an Batch file .bat continue onto the next statement if there is an error.

I'm trying to script the shutdown of my VM Servers in a .bat. if one of the vmware-cmd commands fails (as the machine is already shutdown say), I'd like it to continue instead of bombing out. c: cd "c:\Program Files\VMWare\VmWare Server" vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx suspend soft -q vmware-cmd C:\VMImages\DevEnv\...

Batch file to copy files from one directory to another.

I have two code bases of an application. I need to copy all the files in all the directories with .java from the newer code base, to the older (so I can commit it to svn). How can I write a batch files to do this? ...

Batch script to copy newest file

I need to copy the newest file in a directory to a new location. So far I've found resources on the forfiles command, a date-related question here, and another related question. I'm just having a bit of trouble putting the pieces together! How do I copy the newest file in that directory to a new place? ...

Get a list of all computers on a network w/o DNS

Greetings, I need a way (either via C# or in a .bat file) to get a list of all the computers on a given network. Normally, I use "net view", but this tends to work (from my understanding) only within your domain. I need the names (or at least the IP Addresses) of all computers available on my network. Being able to get all compute...

how can I debug exe with soem switch flags from command prompt

for e.g from command prompt I need to launch the exe with some switch flags under debugger. How do I do it? This is an exe from c/c++ and built using VS2005 environment that I need debug. I pass some flags to this exe to perform some stuff. ...

Shut-down script on Windows to delete a registry key?

EDIT: This was formerly more explicitly titled: - "Best solution to stop Kontiki's KHOST.EXE from loading automatically at start-up on Windows XP?" Essentially, whenever the 40D application is run it sets up khost.exe to automatically start-up with Windows. This is annoying as it increases my boot up time by a couple of minutes and I d...

How can I redirect the output of the executed batch file to a text control, like the CEdit in Visual C++?

I want to execute a certain batch file and redirect its console output to a text control in visual c++ or redirect the console output at the same time the logs/echo are showing. ...

Windows batch command(s) to read first line from text file

How can I read the first line from a text file using a Windows batch file? Since the file is large I only want to deal with the first line. ...

How do I protect quotes in a batch file?

I want to wrap a perl one-liner in a batch file. For (trivial) example, in a unix shell I could quote up a command like this: perl -e 'print localtime() . "\n"' But DOS chokes on that with the helpful Can't find string terminator "'" anywhere before EOF at -e line 1. What's the best way to do this within a .bat? ...

How do I implement quicksort using a batch file?

While normally it's good to always choose the right language for the job, it can sometimes be instructive to try and do something in a language which is wildly inappropriate. It can help you understand the problem better. Maybe you don't have to solve it the way you thought you did. It can help you understand the language better. May...

Stop and Start a service via batch or cmd file?

How can I script a bat or cmd to stop and start a service reliably with error checking (or let me know that it wasn't successful for whatever reason)? ...

How can I load the contents of a text file into a batch file variable?

I need to be able to load the entire contents of a text file and load it into a variable for further processing. How can I do that? Here's what I did thanks to Roman Odaisky's answer. SetLocal EnableDelayedExpansion set content= for /F "delims=" %%i in (test.txt) do set content=!content! %%i echo %content% EndLocal ...

How can I script a no-cost notification of batch file errors/returns?

I have a problem with stopping a service and starting it again and want to be notified when the process runs and let me know what the result is. Here's the scenario, I have a text file output of an "sc" command. I want to send that file but not as an attachment. Also, I want to see the initial status quickly in the subject of the ema...

batch scripting iterating over files in a directory

How could I iterate over each file in a directory using for? And how could I tell if a certain entry is a directory or if it's just a file? ...

batch find file extension

If I am iterating over each file using : @echo off FOR %%f IN (*.*) DO ( echo %%f ) how could I print the extension of each file? I tried assigning %%f to a temporary variable , and then using the code : echo "%t:~-3%" but with no success . ...

How do I test if a file is a directory in a Batch script?

Is there any way to say if a file is a directory? I have the filename in a variable. In Perl I can do this: if(-d $var) { print "it's a directory\n" } ...

What tools are available to measure the "health" of an enterprise web-based system?

I assist in maintaining an enterprise web-based system (programmed in J2EE, but this is a more general question) and I'd like to know: what good tools are out there to measure the "health" of an enterprise system? For instance, tools to check memory space on servers, check the status of batch runs, the number of records processed in a c...

How to check if directory exists in %PATH%?

How does one check if a directory is already present in the PATH environment variable? Here's a start. All I've managed to do with the code below, though, is echo the first directory in %PATH%. Since this is a FOR loop you'd think it would enumerate all the directories in %PATH%, but it only gets the first one. Is there a better way of...

Upgrading DOS Batch files for Windows

Has anyone had any recent requirements for programming automated DOS Batch style tasks on a Windows box? I've got some automation to do and I'd rather not sit and write a pile of .BAT files in Notepad if there is a better way of automating these tasks: mainly moving of files under certain date and time conditions, as well as triggering ...

Windows batch files: .bat vs .cmd?

As I understand it, .bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows, i.e., starting with NT. But I continue to see .bat files everywhere, and they seem to work exactly the same using either suffix. Assuming that my code will never need to run on anyhting older than NT, does it really matter which way I name my ba...