The VBScript Network and Systems Administrator's Cafe:

batch commands

Jan 19 2009   4:14AM GMT

Windows Tip: Clearing Internet Explorer cached data from the command line



Posted by: Jerry Lees
tips and tricks, windows tips, command line, batch commands, batch files, Internet Explorer, rundll.exe, windows secrets, undocumented windows

As a Network Administrator sometimes you need to clear the browsing history, cookies, or the like for a entire community of users. Sure, you could tell them how to do it thinking that you were being super smart by providing instructions for them. However, as you well know there will be some who will be unable to follow the directions and you will spend 3 times the amount of time it took you to write the directions and refine them to a point where any one could do it— or so you thought. All the while, thinking about the amount of time you will save by having the users do it.

Why not be really lazy!!!??!? And do it with a batch script? You could then put it in their login script and it would happen at their next logon, or every logon for that matter. Well, there’s an easy way to do this with windows’ built in functions– it’s just obscure enough to not be found anywhere you would normally look!

Yo can preform many of the things I mentioned (and more) with Microsoft’s RUNDLL.EXE file, plus you don’t have to write a line of VBScript to accomplish the task!

Here is a short list of some tasks you can preform on IE, along with the command to do it… give them a shot!

Temporary Internet Files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

Cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

History
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

Form Data
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

Passwords
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

Delete All
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

Delete All - “Also delete files and settings stored by add-ons”
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

 These commands should work in Internet Explorer 7

Oct 17 2008   11:11PM GMT

Communicating error levels to a calling application from with in VBScript



Posted by: Jerry Lees
VBScript, Error control, exit, on error, errorlevel, WScript.quit, wscript, batch commands

We’ve discussed error handling previously (via the On Error Goto 0 command) in a entry titled, Using error control in a VBScript to recover from odd errors. However, occasionally you need to communicate a condition back to an application or batch file that calls a script as part of its processing. One reason you may need to do this is if you need to call a separate script or application depending on the outcome of the script. You can do this with what is called an error level. Keep in mind this may not have anything to do with an error in the script but can, instead, be used as a method to control how another applicatioin responds to a particular condition.

For example, say you already have a executable that processes a file into a database– but you don’t want to run the executable on a old file because it would cause all sorts of duplicated entries in the database. you might not be able to go back to the person who wrote the executable and have them change it or the executable might not have even been written by the company where you work! You could, however write a script to check the date of a file and if it was created during a time frame return a error level back to a batch file that calls your script and preforms the logic to decide if the executable needed to be ran. Take this batch file for example:

Echo off
cscript Yourscript.vbs
If %errorlevel% == 3 goto runexe
Echo “File to old”
goto EndBatch
:runexe
processingprogram.exe
:EndBatch

This would only run the executable IF your script returned a error level of 3! So you can then preform work and checks never intended by the executable when it was written only if the conditions are correct for it to run.

The line of code in VBScript you would add to your  script to communicate back to the batch file would be:

WScript.quit(3)

This will return a error level of 3 back to the batch file and cause the batch file to THEN run your executable.

So, there you have it! A quick and simple method to extend the life of those aging processes that work fine– just need a minor tweak because your environment has changed.