Link to home
Start Free TrialLog in
Avatar of pdoriley
pdoriley

asked on

Batch Files 101: An Introduction

I want to learn how to write batch files in general and how to assign them as startup or logon scripts in my security policy in Windows XP

For example, something that clears my I.E. cache everytime I boot up.

Can someone introduce me to the art of writing batch files for fun and also give me a practcal example of one that would clear my I.E. cache at user logon?

Below is something I might need for reference:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx



SOLUTION
Avatar of Fatal_Exception
Fatal_Exception
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saadat_saeed
saadat_saeed

you could also use vbscripts or jscripts or even kix (www.kixtart.org) scripts as options!
Lee..  nice explanation and tips, my friend..!!

FE
One thing I've noticed when working with the command prompt is that you have to use the short folder names in the path rather than the long versions.  For example, "xcopy c:\documents and settings\username\my documents\my vacation pics\*.* e:" won't work.  You have to change it to "xcopy c:\docume~1\username\mydocu~1\myvaca~1\*.*".  You can find out the short version by doing a "dir /x".
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've love to know how to echo a backspace in a batch file - look out for it as a seperate thread because I think it deserves points !

Here's the thrust:

echo Deleting file...
del file.txt
echo Done !

Will give a two line result.  Can I echo a backspace to create a result that would show:

Deleteing file... Done !

WITHOUT a cls and re-echo ?


Simon
Hmm..  I don't believe so in this case, not unless you put it in one line...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeesh!  Thanks for the info on cmd.exe.  Why the heck does xp, 2k and nt default to command.com instead?  All this time and I never knew there was a difference - stupid microsoft.   However, I still believe that you must use the 8.3 naming convention when running a batch file.  Unless you can know how to change the default command prompt from command.com to cmd.exe?
Avatar of pdoriley

ASKER

Thanx, so. uh... how do I write a batch file that clears my cookies when I logon to XP again?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To Fatal Exception, thank you:  I'm new to batch files.  
Do I use the command prompt to do this or should I save this in a notepad?

Then type :
Start copy
cd C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files del *.*  
End copy

Save as DelCookie.bat  ( in save as in notepad? or in DOS - HOW do I save it as this in DOS)?


Finally, How do I use gpedit.msc to call it at startup as a logon script?


Thanks again.


actually, the way windows saves temporary internet files and cookies, that wouldn't work.

Open notepad and put the stuff between the lines below in the text file.  Then save it as "cleanupie.cmd"
-------------------------------------
REM The next two lines change into the current user's profile and
REM delete any temporary internet files remaining in their profile.
cd %userprofile%\local settings\temporary internet files\content.ie5
for /f "tokens=1" %a in ('dir /ad /b') Do cd %a & del *.* /q & cd ..

REM The next two lines remove all the cookies.
cd %userprofile%\cookies
del *.* /q
-------------------------------------
Much nicer, lee...  

Regarding gpedit..  If you are working in a domain, the way to do this is with Group Policy, but if you are in workgroup, then the easy way is to use the Local Users and Groups from Computer Management...  In the properties of the user, you can stipulate a logon script to run..  Here is an MS article on this...:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;315245
and now,   do I use the full-style pathname or the short-style pathname.
Thanks, FE.

For my script to work, you must use the cmd.exe command interpreter.  That being the case, long path names SHOULD be fine.  Indeed, when the script is interpreted, it will expand "%userprofile%" to what is most likely "C:\documents and settings\username", so long dir names should be fine.
I only understand 50% on what do to.

I am writing my first batch file and I want it to clear my temp + cookies in I.E., every time I logon to Win XP Pro Sp2/

From start to finish guys, what do I do to write, setup, and execute this batch file..   For example, if I have to save it as  DeleteCookie.bat, how do I do that?

The points will go to the best instructions.  THANK YOU.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
leew, if you show me how to do it with EVERYONE on ONE computer and EVERONE on the NETWORK, I will give you more points!
To add a little to that, if you're REALLY starting from scratch:

Highlight leew's script and copy it into notepad.  Save the file as filename.cmd but when you do this, put it in quotes - ie "filename.cmd" otherwise notepad will add a .txt to the end, which you don't want.
Looks like your questions are answered...  Anything else?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks...   good luck with your new tools..!!  :)

FE