Discussion Locked

Download: Save time using batch files to perform repetitive tasks

0 helpful
49 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

https://www.techrepublic.com.com/5138-10586-729266.html

While batch files are still a viable tool for performing simple day-to-day tasks in a Windows operating system environment, much of their functionality has been supplanted by other scripting languages.

[b]Which do you use more in your day-to-day tasks: batch files or scripts? Can you share an example?[/b]

49 replies

by kolossus

I use batch files to back up the host file and I keep some batfiles in reserve to restore the automatic download and the helpcenter.
Comes quite handy. Maybe I am just an old timer, but I feel they do the job quite well.

by pro-tech

DOS was in its infancy when I got my first IBM clone. If you didn't learn batch language you just couldn't do much with that early PC.
Now I have a website and I have put two very important Batch Files on my website for easy download. They both remove junk files from a PC. Hoover cleans up a win-98,ME PC,and XPCleanup removes all the junk from a Win-XP PC. Download and take a look. Put one in your Startup folder for a daily cleanup.
The Shadow
http://theshadow.members.atlantic.net

by mhasf

I cannot think of a system that doesn't use batch files in some way. I have been using them since 1979 on RSTS/E machines and continued into my Windows Server 2003 world. Back in the days prior to patch kits, you would have to patch a Novell Server by hand... Not this guy! I wrote batch files for updating servers, so I would not miss anything and more importantly, ensure that everything got copied into backup directories.

In LINUX I guess they're called scripts, and they are invaluable! I think a good IT person ought to be a little lazy so as to be motivated to automate everything. (sounds like an oxymoron, eh?)

by bcccprof

In XP, RD has a switch /s that replaces deltree.

Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.

/Q Quiet mode, do not ask if ok to remove a directory tree with /S

by locedup1

Hi there,
I saw that you have 25 years of scripting under your belt, and I have 0. I have never programmed at all. I need some help, badly. I need to create a batch file to FTP information from a Unix server, dump the infor into a specified directory, then say goodbye.

We are basically porting a Unix app to windows, so I need to automate movement of data from one server to another. I am sure that you are porbably laughing, because it may prove a simple task for someone like you.

I would appreciate you pointing me in a direction that may help me accomplish this task.

Thank you very much.

by jim

This batch assumes that you have a shared folder (share) on a pier machine (\\workstation)

NET USE /D X:
NET USE X: \\WORKSTATION\SHARE /PERSISTENT:YES

if you need to log in to workstation with a different username use /USERNAME:user at the end

by hawk

I still use batch files to automate functions for my business customers, I specialize in Mom & Pop startups and use them too simplify multifunction tasks that would otherwise cause confusion and repeated help requests.

by rayjeff

I remember going to the MSDN site to find all of the commands for batch filing in MS-DOS. The problem is I can't seem to find it again. Does anybody know of or have the link to it? I'm still searching as I type. But I do remember seeing it and actually saving it.

by support

Many new ideas how to do batch tasks is possible to found with package Task3000. This includes innovative new techniques with GUI, input and output queue, built-in scheduler, File RC and much more. Usage is very simple and efficient; package can be treated as add-on to any scripting language. It includes Task3000 Menu, which enables users to do the job with GUI and Task3000 Workstation, which is used to develop the tasks.
Learn new techniques to do old job with GUI environment.

Regards

by anil4992

HELLO EVERYONE,i USE BATCH FILE TO UPDATE MY ALL SERVERS.I MANUALLY DOWNLOAD DAT FILE TO A LOCATION THEN BATCH FILE CONNECT AND UPDATE ALL SEVERS BY USING SCHUDULE TASK.

by rameshwar1

If you have multiple datxxx.exe available on a location how you will run the latest datxxx.exe from all the datxxx.exe.

If you have the script please send me to rameshwar1@yahoo.com

by jacksonian

What qualifies someone as an old timer? I dont consider myself an "old timer", but I agree with your statement that "they do the job quite well". Batch files are indispensable. And with Nomad technology cominf our way, the god old command line just might make come back from the dead!

by dale.rivers

Batch files are fine, but if you need to do anything serious but still need to develop quickly and easily, it is surpassed in every way by AutoIT. Free software and very powerful. If a batch file is larger than 4 lines, use AutoIT - check it out.

by somethinggood4

AutoIT is a very ueseful, very powerful program. I'm just learning about VB and have not been able to take full advantage of its capabilities, and I've already found it nearly indispensible! The compiler makes it possible to deploy your batch as a single executable, which makes it simple for newbies and ties nicely into Scheduled Tasks in Windows. I recommend it!

by jsbowen

I use batch files more frequently, as they provide a simple solution for certain tasks. I currently have several batch files doing several different tasks. One of the most important batch files copies a simple html file to the web server so that users know when I'm in the office and when I'm not.

Another batch file of great importance automatically updates our bayesian database to learn the difference between spam and ham.

All the batch files I use do simple, simple tasks that would otherwise consume 5-10 minutes per day. However, I setup task scheduler to keep them running and forget about them.

Online batch:
del "\\Fs1\SYS\Apache\nwdocs\web\login.html"
copy "\\Fs1\Vol1\Firm\shared\JSB\web\login.html" "\\Fs1\SYS\Apache\nwdocs\web\login.html"
exit
end

Offline batch:
del "\\Fs1\Sys\Apache\nwdocs\web\login.html"
copy "\\Fs1\Vol1\Firm\shared\JSB\web\logout.html" "\\Fs1\Sys\Apache\nwdocs\web\login.html"
exit
end

SpamAssassin auto-learn:
sa-learn --spam \\\Fs1\VOL1\Firm\Shared\JSB\Software\Guinevere\BAYES\FILES\SPAM
sa-learn --ham \\\Fs1\VOL1\Firm\Shared\JSB\Software\Guinevere\BAYES\FILES\HAM
del \\FS1\VOL1\Firm\Shared\JSB\Software\Guinevere\BAYES\FILES\SPAM\*.* /Q
exit
end

by softwarearchitect

For years I have been running SQLServer backups automatically, and witrhout the need for expensive "SQLServer support" simply by using a batch file, a SQL script, and the NT/2000/XP scheduler service.

Part 1 - SQL Script
Save the following text to a file named backup.sql (you will need to edit the @backup_path variable for your system).
-------------------
set nocount on
declare @sql varchar(255)
declare @backup_path varchar(255)

set @backup_path='X:\SQLServer\Default\Backup'

declare c100 cursor for
select convert(varchar(255), 'use '+name+' exec sp_helpdb '+name+' dbcc checkdb('''+name+''') backup database '+name+' to disk='''+@backup_path+'\'+name+'-1.sqldmp''')
from master..sysdatabases
where name not in ('tempdb', 'Northwind', 'pubs')
order by name

open c100
fetch c100 into @sql
while @@fetch_status = 0 begin
print ''
print @sql
print ''
exec(@sql)
fetch c100 into @sql
end

close c100
deallocate c100
-------------------

Part 2 - Batch file
Create a batch file to run the backup.sql command. You can adjust the number of days of backups to retain, as you desire. Call this BackupSQL.cmd.

@echo off
-------------------
X:
cd \SQLServer\Default\
echo %date% %time% >> backuplog.txt

cd Backup

del *-3.*
ren *-2.* *-3.*
ren *-1.* *-2.*

osql /E -i ..\backup.sql -E -w500 -n >> backup-1.log
cd ..
-------------------

Part 3 - use the Windows scheduler.
You can use the at command or the ResourceKit's GUI. Here is the at command for scheduling this daily, at 3:00 AM:

at 3:00 /every:M,T,W,Th,F X:\SQLServer\SQLBackup.cmd

The resultant *.sqldmp files can be backup up to tape or network as desired.

by harshaabba

thanks lot for ur script it work fine
but i need to modify this coding slightly
i need to get my backup to another server which ip reside 10.0.64.180. i create a folder called Backup in my C partition and share it.
then i change my backup path to \\10.64.10.180\Backup
but it didnt work
so can u gv me a hint very soon
my e-mail:harshaabba@gmail.com
thanks

by plindber

A big part of HIPAA (Healthcare Privacy & Security - Fed. Gov.) is to log user?s access and review it for "anomalies". This has the potential of becoming a time consuming task. I was thinking that a good batch file to copy the logs somewhere, sort out the issues, and save the results for later review, (or email it to me), would be a good solution. Then I wouldn?t have to ?house clean? to keep the files from piling up, and I would only have to deal with the problems without sifting through everything.

I have no experience working with batch files. About 20 years ago I did some programming in FORTRAN, and Pascal, (and played a bit with Basic), but haven?t touched it since I moved into sys. admin. How much effort would it be to pick this up? And does this idea lend itself to what I need to deal with?

by eliant

See if you can figure out what this BAT file (named COMPF.BAT) did for me in the old days (and even today, once in a great while.)

========
fc /c/n/w %1 %2>compf.lst
========
(scroll down for answer)

With this BAT file in \Windows\Command, you can compare two very similar files (good for locating the differences in version1 and version2 of text files.

Results are dumped to file COMPF.LST in your current directory.

by eliant

Compare the contents of two directories using the following BAT file and typing DIRCOMP DIR1 DIR2 at the command prompt.
=============
dir %1 > c:\temp\dir1.txt
dir %2 > c:\temp\dir2.txt
fc /c/l/n c:\temp\dir1.txt c:\temp\dir2.txt > c:\temp\dircompf.txt
edit c:\temp\dircompf.txt

by mentzel.iudith

Yes, batch files are a main part for any of our
projects.
I worked for years in a VMS (Digital) environment,
where for writing batches you have a real language
, DCL, at your disposal. And I really did very
clever things using it, considering that we do a
lot of back-end data processing.
After moving to the WINDOWS environment, I felt
like an orphan child if I compare the simple DOS
commands to the very extended DCL commands.
So I started to use scripts, mainly VBscripts.
But, still, performing operating system tasks,
like scheduling a.s.o. is far from being
satisfactory.
Yes, for almost everything there are 3-rd party
tools/software available, but they cost a lot of
money, licenses, a.s.o., so you pay a lot for
something that was once built-in into the
operating system...
I think that all the WINDOWS world, in spite of
its nice graphical interfaces, has still a lot to
learn from the old good mainframe world, before
burying it...

by transit_admin

if you use the following command, you can have an input from the user after the batch file starts.

copy con C:\input.txt
for /f "tokens=1 delims= " %%a in (C:\input.txt) do set INPUT_VAL=%%a

This will take the input from the user and set the value to the variable %INPUT_VAL%. The tokens has to be set according the whether you are taking one, two, etc variables from the user and then the delims is set according to how you separate the variables. The user will have to type in the variables according to how you have the delims set. The user then presses F6 and enter to stop the keyboard input wait. F6 is the same as ^Z, which is CTRL+Z.

While there are other solutions out there, this has been the most consistent that I have found.

by jacksonian

Ghanshyam,

If you are using Windows 2000 or later, try using the set command. Here is how:

= Batch start =========
ECHO.
ECHO You may share any desired folder
ECHO.
SET /P share=Enter Share Name:
SET /P location=What Do You Want To Share?
ECHO.
ECHO. Example: C:\Winnt
ECHO.
net share %share%=%location%
ECHO.
ECHO Adding Share name %share% for %location%
ECHO.
PAUSE
= batch end =========

If you look at my example above, the set /P command is what asks for user input. After you type set /p, the next word you type will be a variable you create for using later on in your batch file. Then, ensure you use an equal sign, and immediately after that, type in what you want your users to see.

Hope this helps you ...

by ktazz

I know how to create a batch file that connects user to home folder. How do I create a desktop shortcut for that home folder("H" drive) for students no matter who logs into a computer. Any help greatly appreciated.

by jacksonian

Ktazz,

I have a suggestion for you. Get the shortcut.exe utility from

http://www.optimumx.com/download/Shortcut.zip

For your answer, you need to include a mechanism in your batch file to copy the shortcut.exe file to the users workstation when they login. You can it this way:

IF NOT EXIST %SYSTEMROOT%\SYSTEM32\shortcut.EXE COPY \\(servername)\(sharename)\shortcut.EXE %SYSTEMROOT%\SYSTEM32 > NUL

You will have to put the utility in a share (sharename) on a server (servername) for the users to copy it when they login.

After that, include this line in your login script to actually make the shortcut to your users H: drive:

SHORTCUT -f "%userprofile%\Desktop\%username%.lnk" -t "H:\"

I hope this helps you. If you run into any problems (with the syntax), please let me know jacksonmn@3mawyuma.usmc.mil

by hostilio

Hello,

I want to know if it?s possible to create batch file
to any programs for display username and password. I want to put username and password when access to isa server 2004 standard edition.

by jacksonian

Mhasf,

I agree completely with your statement that a "good IT person ought to be a little lazy so as to .. automate things".

My philosophy, a good network admin should never have to leave his chair (unless its for coffee).

My first PC came with DOS 5.0 and alot of the "new generation", to include my colleagues, know nothing about the importance of the command line. I have 100's of scripts in my library and I enjoy the challenge of finding a way to automate every task, not just the mundane, from my little blinking cursor ...

by somethinggood4

Automation is the way to go! Our office has been undergoing a data revolution over the past two years... Our reporting had been delivered on paper for ever, and when I took over Admin, I set about freeing us from the task of transferring that info to our analysis spreadsheets. That led to a moacro in the spreadsheet program that aoutomated the update process, and a script that automatically runs the macro. Now that we've gone paperless, I'm looking at developing a script (or batch) that will do all of our digital filing for us on a schedule. Lazy? I call it efficient!

by jacksonian

locedup1,

Try this for your ftp automation. It is a script used to automate the download of antivirus signatures for symantec. You will need 2 files. One is your batch file that will initiate the ftp process and two is the ftp script that will issue commands. I have the batch file listed first, and i included comments to let you know whats happening and how you should modify. I will make my comments using <==, so make sure you remove <== and everything after that (to the right).

=ftp batch file start =========
ftp -s:script.txt <== calls ftp automation
<== enter what you want you want to accomplish
<==after the files are transferred here.

=script.txt start=========
open ftp.symantec.com <== opens an ftp site
anonymous <== username here
nobody@spammer.com <== password here
cd /remote/directory <== change directory (remote)
lcd C:\temp <== change directory (local)
bin <== set binary transfer mode
hash <== show hash symbols during transfer
prompt
get filename.exe <== filename that you want to get
quit <== quit the ftp session

This is just a basic suggestion. You can elaborate as much as you need to. If you need further help with this, shoot me an e-mail at jacksonmn@3mawyuma.usmc.mil.

Hope this helps!

by jacksonian

Instead of using MSDN, try Rob Van der Woude's site: http://www.robvanderwoude.com/

If you look at the frame on the left, he has a section for Batch files (its at the top). He has excellent information on batch files and commands for beginners and experts.

by gregory.c.fisher

When I try to run the dskchk bat file I get an syntax error at the line "If not errorlevel 3 goto defrag". Anybody have an idea? I'm running XP Pro and I have administrator rights.

by jacksonian

Greg,

Did you make sure that you included the drive letters in this format in your DrvLtr.txt file?

C:
D:
end

Make sure that you include the ":" and make sure you hit enter after each ":". Also ensure you hit enter after the "d" in the word end.

If it still doesnt work, let me know ...

jacksonmn@3mawyuma.usmc.mil

by emar1000

Jackson,
Here is what I have....

REM chkdsk and defrag automation
for /F "eol= tokens=1 delims=( " %%i in (DrvLtr.txt) do set DrvLtr=%%i& call
:dsKchk

:dsKchk
If %DrvLtr% == end goto :eof
chkdsk %DrvLtr%
If not errorlevel 3 goto :defrag
If not exist %DrvLtr%\winnt If not exist %DrvLtr%\windows If not exist
%DrvLtr%\pagefile.sys goto :dskchkon

:dskchkoff
cd\ %DrvLtr% echo Y chkdsk /F /R
goto :defrag

:dskchkon
chkdsk %DrvLtr% /F /R

:defrag
cd\
%DrvLtr%
defrag %DrvLtr% -b
defrag %DrvLtr%
:EOF

There are no spaces after the lines. And I made the Drvltr.txt as you stated. When I run the cmd it just pops up fast and goes away and thats it. Nothing else happens. Possible fix?

A little new to batching so please go easy on me. :)

Thanks E

by deurich

This is a batch file I created to remove unwanted hardware and software from a machine. We use Ghost images with SysPrep to consolidate an image that works on all models of machines (Desktop/Laptops) within our corporation. I use specific batch files like this one to remove unwanted hardware and software from a machine once they have been re-imaged.

I like script and batch files that are well documented??.a bad habit I picked up since the early eighties programming PCL Logic and CNC logic. Every admin. should be using scripting and batch programming no mater what OS or TTL logic they run.

This batch calls specific hardware and software that indigenous to our corporate environment but you get the idea of the logic. I have since corrected the images to load only the specific hardware on a specific machine. I still use a modification of this batch file to remove unwanted software. Batches and Scripts are the savior of repetitive tasks in our logical world.

This batch file removes applications that are not used on desktops by uninstalling the program through
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall registry key.

echo ****************************************************************
echo * This batch file will remove apps not used on a desktop image *
echo * If you have any questions please contact a member of the *
echo * Hardware Team for help
echo * DO NOT REBOOT DURNING THESE UNISTALLS. *
echo * WAIT TILL DOS SCREEN SAYS "PLEASE REBOOT SYSTEM NOW "
echo ****************************************************************
pause

:Removes Toshiba Software Modem
s3uninst.exe -reg 5 'HKLM\Software\S3\S3Uninst\S3Info2'

:Removes Conexant D480 MDC V.92 Modem
C:\Program Files\CONEXANT\CNXT_MODEM_PCI_VEN_8086&DEV_24x6&SUBSYS_542214F1\HXFSETUP.EXE -U -Idel5422k.inf

:Removes S3Info2
s3uninst.exe -reg 5 'HKLM\Software\S3\S3Uninst\S3Info2'

:Removes S3Gamma2
s3uninst.exe -reg 5 'HKLM\Software\S3\S3Uninst\S3Gamma2'

:Removes S3Display
s3uninst.exe -reg 5 'HKLM\Software\S3\S3Uninst\S3Display'

:Removes Broadcom Driver Installer
C:\PROGRA~1\COMMON~1\INSTAL~1\Driver\7\INTEL3~1\IDriver.exe /M{BE6890C7-31EF-478C-812E-1E2899ABFCA9} /l1033

:Removes Broadcom ASF Management Applications
C:\PROGRA~1\COMMON~1\INSTAL~1\Driver\7\INTEL3~1\IDriver.exe /M{25D24E84-64A9-40D2-85CF-540B1C4A6D52} /l1033

:Removes Access Finder 3.3
C:\WINDOWS\ISUNINST.EXE -f"C:\Program Files\XO Communications\Access Finder\Uninst.isu" -c"C:\Program Files\XO Communications\Access Finder\Uninst.dll"

:Removes Dell ResourceCD
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{D78653C3-A8FF-415F-92E6-D774E634FF2D}\setup.exe"

:Removes QuickSet
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{C5074CC4-0E26-4716-A307-960272A90040}\setup.exe" -l0x9

:Removes ALPS Touch Pad Driver
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{9F72EF8B-AEC9-4CA5-B483-143980AFD6FD}\setup.exe" UNINSTALL

:Removes Cisco Systems VPN Client 3.6.6.a (Rel)
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{5624C000-B109-11D4-9DB4-00E0290FCAC5}\Setup.exe" -l0x9 VpnUninstall

:Removes Cisco Systems VPN Client 3.6.6.a folder from HD
RMDIR /s /q c:\PROGRA~1\CISCOS~1\

:Removes Cisco Systems VPN Client 3.6.6.a icon from desktop
del "C:\Documents and Settings\All Users\Desktop\VPN Client.lnk"

:Removes Compaq Wireless LAN
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\PROFES~1\RunTime\0701\Intel32\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{70563F48-07E8-4AD0-B3FB-23257E5C8B72}\setup.exe" -l0x9 -a

:Removes SigmaTel AC97 Audio Drivers
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\PROFES~1\RunTime\0701\Intel32\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{7959721D-8268-4565-9E0E-C41A9F4848A9}\setup.exe" -l0x9 -nodialog -uninstall

:Removes DVD-RAM Driver
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\engine\6\INTEL3~1\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{9D765FA6-F2BC-40AF-8145-50808F9BDF4E}\Setup.exe" DVD-RAM Driver

:Removes Compaq Client Manager
RunDll32 C:\PROGRA~1\COMMON~1\INSTAL~1\PROFES~1\RunTime\0701\Intel32\Ctor.dll,LaunchSetup "C:\Program Files\InstallShield Installation Information\{EDC2FD00-D743-11D4-969D-0060B0FBF2F6}\setup.exe" -l0x9 -a

:Removes TOSHIBA Software Modem
Tosmreg -SU

:Removes ATI Video Drivers
rundll32 C:\WINDOWS\System32\atiiiexx.dll,_InfEngUnInstallINFFile_RunDLL@16 -force_restart -flags:0x2010001 -inf_class:DISPLAY -clean

:Removes ATI Video Software
C:\Program Files\ATI Technologies\UninstallAll\AtiCimUn.exe

pause

echo PLEASE REBOOT SYSTEM WHEN YOUR READY!

pause
:quit

by matt.yamkowy

I did a lot of patching against multiple computers with batch files back in the day. I had a batch that would go through every computer and patch them one by one. it was slow.

So I build a little app, that takes a batch file, and executes multiple threads of it. Speed up my patching a ton!

So here is how it works:
batproc.exe <# of threads>

then batproc executes like this:

etc.

its not to shabby, but the output isnt always the greatest. but if anyone wants to give it a try your welcome to try:
http://mlogic.mine.nu:81/batproc.exe

by demo_dog

A simple batch file, along with a useful tip. Not all commands write to stdio.
Route.exe is onesuch. route /?|more still runs off the page.
route 2>&1|more is useful. Other commands do the same.
Listing for man.bat, an easy way to view all the switches of a command whether it writes to stdio or not

@echo off
if "%1"=="" goto :pages
set file=%1
if exist h:\manpages\%file%.man goto :view
%file% /?>h:\manpages\%file%.man 2>&1
:view
type h:\manpages\%file%.man |more
goto :eof
:pages
dir h:\manpages\*.man
goto :eof
:eof

by visualsun

I had the same issue, i had to make sure that the lines were not wrapped..

these lines should be one line...

===========================================
for /F "eol= tokens=1 delims=( " %%i in (DrvLtr.txt) do set DrvLtr=%%i& call
:dsKchk
===========================================
If not exist %DrvLtr%\winnt If not exist %DrvLtr%\windows If not exist
%DrvLtr%\pagefile.sys goto :dskchkon
===========================================

The only problem i get is it tells me that checkdsk is not running with the /F switch even though the code shows chkdsk %DrvLtr% /F /R ... so go figure whats up there....

by Member 22194997

so no need for the /F switch (the Recovery includes the Fixing of errors).

There are other switches available for the CHKDSK utility and to see them all you have to do is open a command prompt and type in CHKDSK /? to get a full list of them and proper syntax.

by gkap

Hi people! I am having trouble with the following seemingly simple batch file:

"C:\Program Files\MSN Messenger\msnmsgr.exe"
"C:\Program Files\Yahoo!\Messenger\ypager.exe"
"C:\Program Files\Microsoft Office\Office10\OUTLOOK.EXE"
"C:\Program Files\Internet Explorer\iexplore.exe"
exit

Now, the batch file opens MSN msgr, then stops after it opens Yahoo messenger, and then will only progress to opening Outlook if i close Yahoo msgr. Further, once i do that, and Outlook opens, the batch file then does not proceed to the next line - opening internet explorer - until i close outlook!! Can someone pls give me a solution to this so that all of them open consecutively?!!

by home4ktt

You need to use the START command.
Use "START /?" to get the full Help page.
So it would go something like...

start "Msn" /min "C:\Program Files\MSN Messenger\msnmsgr.exe"
start "Yahoo" /min "C:\Program Files\Yahoo!\Messenger\ypager.exe"
start "Mail" /min "C:\Program Files\Microsoft Office\Office10\OUTLOOK.EXE"
start "IE" /min "C:\Program Files\Internet Explorer\iexplore.exe"
etc.

by pcrepairguy08

The reason your script fails is:

Batch Scipt files read each line by line making it Simple to create and use for everyday tasks.

Batch scripts wait for each command in the line to complete then read the next line below.
There are other ways around this problem like using call or goto commands
example: Call :%1
example: goto :END

This is easy to fix. Try it this way.

@start "" "C:\Program Files\MSN Messenger\msnmsgr.exe"
@start "" "C:\Program Files\Yahoo!\Messenger\ypager.exe"
@start "" "C:\Program Files\Microsoft Office\Office10\OUTLOOK.EXE"
@start "" "C:\Program Files\Internet Explorer\iexplore.exe"

or if you want to wait for the line to finish its task before continuing use

@start ""/Wait "%ProgramFiles%\Internet Explorer\iexplore.exe"
reason I am Using start ""

start "" "C:\MyExample\YourFile.exe"

you are using "" after start.exe for blank spaces/white space in the path to the file you want to execute.

If there is no White Space / Empty Space in file path you wont need == start "" just
start C:\MyExample.exe

By using Start command will execute each item without stopping and waiting,
but it has that option. using start /wait

Hope this helps anyone trying to figure out Batch Scripting.

Jason Swartz,
PcMedix Consulting Services.
Dallas, TX

by ddawson5

I created a handy little script for my users too lazy (including me) to backup regularly. It copies any new or changed files from My Documents (or any folder you choose) to our shared (and backed up) server (or any drive letter location).

xcopy "C:\Documents and Settings\\My Documents S:\Backup (or any Drive Letter, connected shared drive, external, etc) /D /S

XCOPY copies all files and folders including subdirectories
the /D switch copies only files that are new or newer than the file or files that exist in the destination
the /S switch copies all directories and subdirectories EXCEPT empty folders.

I even have this run as a scheduled task once a day. Sure beats running that backup program once a week. Hope you can use it!

by catseverywhere

Thank you, ddawson. Your short, sweet script is EXACTLY what I needed.

I have been trying to set up a Linux backup server that will use rsync over ssh to grab files off of Windows (XP) machines.

The ssh servers for windows leave much to be desired, such as syntax to change to directories with spaces in them is a real bear, I have not been able to automate a change to "C:\Documents and Settings" remotely.

No need now. I'll use your simple batch to push the files locally on the Windows machines to the ssh server root first! (e.g. C:\cygwin\bak)

Then it's a simple matter to use a password-less key to shell in to XP and grab the whole "bak" folder.

Thanks again. I don't relish having to touch anything Windows, and this request was driving me nuts! ...ever see the Linux ssh syntax for handling blanks in filenames? Ridiculous.

cat

ps- I'm from Rochester, originally. Nice town, I miss it.

by jpjones23

I recently created a MS Word based tool that comments out production servers in the Hosts file, copies test servers into it and runs a batch file to refresh one's PC to find the updated Hosts file. Before updating the Hosts file it gets backed up so that one can select a second button in the tool to restore it as if it was never touched. If you'd like a copy of the tool and the batch file, email me at work (jeffrey.p.jones@eds.com) and I'll share both with you.

Jeff

by veig56

Here are my version :

echo Y chkdsk /F /R
is replaced by : echo Y| chkdsk %DrvLtr% /F /R

goto :defrag
is replaced by : goto :EOF
because I think it's not a good idea to defrag if chkdsk does not correct filesystem mistakes

chkdsk %DrvLtr% /F /R
is replaced by : chkdsk %DrvLtr% /F /R /X

Very useful batch. Thanks.

by gevanson

I work at a school. The teachers who use the classroom like to have several shared folders that all students can see to take and store class related data. To keep things simple I map two folders on my server as virtual drives. This can easily be done using the Net Use command. Micrsoft's article id: 308582 covers use of Net use for anyone who has not run across it.

This discussion is closed to new replies.