Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - restart service and email

Reply
 
Old 04-24-2009   #1 (permalink)
sjkraal


 
 

restart service and email

I need a script that I can call from the service recovery options.
I need it to start the crashed service.
Get the relevant event from the system event list.
Send an email with the event in the body.

Does anyone have something like this?

My System SpecsSystem Spec
Old 04-25-2009   #2 (permalink)
OldDog


 
 

Re: restart service and email

On Apr 24, 5:07*pm, sjkraal <sjkr...@xxxxxx> wrote:
Quote:

> I need a script that I can call from the service recovery options.
> I need it to start the crashed service.
> Get the relevant event from the system event list.
> Send an email with the event in the body.
>
> Does anyone have something like this?
This might get you started;

# COMMENT: Check if Process is running. If not start it and send an
Email
#
#
==============================================================================================
if (!(gps myproc -ea 0)) {
$MyProcCMD = "c:\program file\my program\myproc.exe /switces"
#<-- cmd to start proc
$wmi = ([wmiclass]"win32_process").Create($MyProcCMD)
if ($wmi.returnvalue -eq 0) {
$smtp = new-object system.net.mail.smtpClient
("smtp.domain.com")
$mail = new-object System.Net.Mail.MailMessage
$mail.from = "f...@xxxxxx"
$mail.to.add("t...@xxxxxx")
$mail.subject = "MyProc was in Stopped state. Successfully
restarted."
$mail.body = "bla-bla-bla"
$mail.IsBodyHtml = $true
$smtp.send($mail)
}

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Services Problem. Have Stopped a service..now can't restart it. Help Plz! General Discussion
Controlling service restart timeout with WMI VB Script
vista - keep needing to restart dns service Vista networking & sharing
Email causing restart Vista mail
How do I restart the service of Windows Security Center? Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46