Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB script to run Exchange Eseutil defrag on remote computers

Status
Not open for further replies.

BobSakemano

Technical User
Feb 17, 2005
20
0
0
NL

I need a script that does the following things:
Dismount Exchange Information Stores
Run Eseutil /d
Mount Exchange Information Store

So far I’ve been working with send key commands in my script:

Option Explicit
Dim objShell, Racey, Count
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd"

If 1 = 1 then
objShell.SendKeys "net stop Microsoft Exchange Information Store"
objShell.SendKeys "{ENTER}"
objShell.SendKeys "cd c:\program~1\ Exchsrvr\bin\"
objShell.SendKeys "{ENTER}"
objShell.SendKeys "eseutil \d c:\program~1\ Exchsrvr\MDBDATA\priv1.edb"
objShell.SendKeys "{ENTER}"

end if

This doesn’t work ofcourse because the Net Stop command is wrong, it should be "net stop "Microsoft Exchange Information Store"" (with double quotes on the service).

But the vbs doesn’t like this and gives me an error: Expected End Statement.

Can you guys help me with this, I’m sure there is a much easier way.


 
And this ?
objShell.SendKeys "net stop ""Microsoft Exchange Information Store"""

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
yes that worked thanks. Now the problem is that after I Net Stop the Exchange Information Stores they are dismounted like I want to so that defrag can be run but when I Net Start the service the information stores are still dismounted?! Thats not what I want.
 
Got that working myself actually.

Now I just want an alternaive instead of theSendkey object. It doesnt work because it runs all of the commands simentaneously.

So is there any other way to run:

net stop "Microsoft Exchange Information Store"
cd c:\program files\Exchsrvr\bin\ eseutil /d c:\program~1\Exchsrvr\MDBDATA\priv1.edb
net start "Microsoft Exchange Information Store"

In a vbs?
 
Hi BobSakemano,

You can use the objShell.run method and wait for it to return.

object.Run (strCommand, [intWindowStyle], [bWaitOnReturn])

bWaitOnReturn :Optional. If bWaitOnReturn is not specified or FALSE, immediately returns to script execution rather than waiting for the process to end.
If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.
If bWaitOnReturn is not specified or is FALSE, the Run method returns an error code of 0 (zero).

For example
Code:
strCmd = "cmd /C net stop "& """" & "Microsoft Exchange Information Store" & """"
freturn = WshShell.run(strCmd,0,TRUE)

Hope this helps...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
you want to be careful with the use of Net Stop and Net Start from the shell. under some circumstances they will prompt for user input, i.e. "Service blaa relies on this service, stopping this service will...blab blab"

'stop the winmgmt service
Set objService = objComputer.GetObject("service", "winmgmt")
If objService.Status = 4 Then
objService.Stop
End If
Set objService = Nothing
 
BobSakemano

do you have a finished script ?

I would love to add this one to the tool box

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top