Solved

Batch Script how to

Posted on 2007-12-02
10
460 Views
Last Modified: 2010-04-16
I have this Batchfile below that will flush the cache of everyones Outlook Cache when you click on it.

I'm trying to get this thing to run on about 300 computers but cannot use a GPO to push it out.

I also cannot throw it in the start menu of users machines because it will run all the time.

Does anybody have a way to run this just once on 300 client computers with no user intervention?

Thanks for your help

taskkill /IM OUTLOOK.EXE
del "C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Outlook\Outlook.NK2
outlook.exe"
^z
0
Comment
Question by:snyderkv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 20391225
This is "Per User", so it won't help you to run this "once on 300 computers"; you need to run this once per each user on each of the 300 computers.
Put the script below into the logon script or wherever; it uses a "flag file" to indicate whether the cache still needs to be deleted or not.
Note that "C:\Documents and Settings\%USERNAME%" is NOT the correct path to address the user's profile; the user's profile path is in %UserProfile%.
Then there's a dedicated variable "AppData" on machines running W2k or later that points to the user's application data folder, which is the one to use here.

set FlagFile=%Temp%\OutlookCacheDeleted.flg
if exist "%FlagFile%" goto CacheDeleted
  taskkill /IM OUTLOOK.EXE >NUL
  del "%AppData%\Microsoft\Outlook\Outlook.NK2
  echo %Date% %Time% >>"%FlagFile%"
:CacheDeleted

Open in new window

0
 

Author Comment

by:snyderkv
ID: 20391263
oBda,

Wow thanks for the updated script.

But remember I can't use a Logon GPO script.

I wonder if I can run this in psexec? I can incooperate this in that and have it run through a list of computers?

Thanks
0
 
LVL 85

Expert Comment

by:oBdA
ID: 20391299
There's nothing that would stop you from using a GPO logon script (or the regular logon script).
The current version I posted above takes care that it will only delete the cache if it hasn't been deleted before.
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

Author Comment

by:snyderkv
ID: 20391623
Actually I'm saying that I really can't use the GPO script because it's forbiden by upper management.

I know I can use your script in another way though. How would you suggest.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 20391729
You can basically use any way you have at your disposal to run this script during logon of a user.
You can of course run it remotely against a list of machines as well (and you don't need psexec for it), but that's more complicated, because machines can be turned off, the users may be using Outlook at the moment you're running the script, the folder might be redirected ...
This script will only echo the taskkill and delete commands it would otherwise run. Remove the CAPITALIZED echo commands to run it for real.

@echo off
set MachineList=machines.txt
set LogFile=FailedMachines.txt
if exist "%LogFile%" del %LogFile%"
for /f "tokens=1" %%a in ('type "%MachineList%"') do call :process %%a
echo Done.
goto :eof
 
:process
set Machine=%~1
echo Processing %Machine% ...
ping -n 1 %Machine% | find /i "TTL" >NUL
if errorlevel 1 (
  echo ... not responding!
  >>"%LogFile%" %Machine%
  goto :eof
)
for /d %%a in ("\\%Machine%\c$\Documents and settings\*.*") do (
  echo ... checking %%a ...
  if exist "%%a\Application Data\Microsoft\Outlook\Outlook.NK2" (
    ECHO taskkill /s %Machine% /IM OUTLOOK.EXE
    ECHO del "%%a\Application Data\Microsoft\Outlook\Outlook.NK2"
  )
)
goto :eof

Open in new window

0
 

Author Comment

by:snyderkv
ID: 20391777
Wow fantastic. How come I never get employees that know this stuff.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 20391808
Just noticed that there's a quote missing in line 4, right before the second "%LogFile%"; should look like this:
if exist "%LogFile%" del "%LogFile%"
0
 

Author Comment

by:snyderkv
ID: 20392055
So besides the Machine List names that I do manually, do I have to do anything for the &LogFile% ?

So I can just run this from my desktop with my list of computer names ?

Thanks again
0
 

Author Comment

by:snyderkv
ID: 20392070
Nevermind LogFile is the list of machines it outputs after pinging them.

Sorry
0
 
LVL 85

Expert Comment

by:oBdA
ID: 20392468
LogFile is the list of machines that haven't reacted to the ping, that is, these are the machines that still need to be processed at some other time.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question