' Process.vbs
' VBScript Win32_Process to discover which processes are running
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.4 - December 2010
' -------------------------------------------------------'
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Found="NO"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcess
'''''''''''''Check the Process Name'''''''''
IF trim(objProcess.Name) = "YOUR_PROCESS_NAME" THEN
Found="YES"
END IF
'''''''''''''END'''''''''
Next
IF Found = "NO" THEN
'Trigger the email - use blat or bmail utility
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "blat -to abcd@xyz.com -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True
'clear out wshshell variable
set wshShell = Nothing
END IF
WScript.Quit
' End of List Process Example VBScript
Thanks for update, In the code i'm facing issue details given below please suggest.
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop\check.vbs(10, 1) Microsoft VBScript ru
ntime error: Variable is undefined: 'Found'
C:\Documents and Settings\Fareedm\Desktop>
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
to
Dim objWMIService, objProcess, colProcess,WshShell
Dim strComputer, strList,Found
Thanks for update seems script is executing but the issue is i'm not reaciving the email while running the script.
C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMME
25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME time(s)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop>
can you put below line before the WScript.Quit and check what is the value of the Found variable.
msgbox Found
Also, you can print the process name ( inside the For Each loop) and check whether the expected process name is coming or not
For Each objProcess in colProcess
'''''''''''''Check the Process Name'''''''''
WSCript.Echo objProcess.Name
IF trim(objProcess.Name) = "YOUR_PROCESS_NAME" THEN
Found="YES"
END IF
'''''''''''''END'''''''''
I'm sorry i din't change this line, I put the process name oracle and tried, seems issue is same, Because when i'm trying check the oracle process in task manager its not showing , when i'm doing
dim WshShell
dim f,fso,Filename
Const ForReading = 1
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'run the command and redirect
WshShell.Run "cmd /c tasklist.exe |sort > C:\\tlist.txt", 2, True
Filename = "C:\\tlist.txt"
Set f = fso.OpenTextFile(FileName, ForReading, True)
FileText = f.ReadAll
f.close
IF InStr(FileText,"oracle.exe") = 0 Then
'Trigger the email - use blat or bmail utility
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "blat -to abcd@xyz.com -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True
'clear out wshshell variable
set wshShell = Nothing
END IF
WScript.Quit
Thanks for your efford on this Issue,I'm very much happy to find valuble soulutions.
I tried the below given code but i'm not reaciving email with this.
Also tried option of check option, its showing the blank window.
msgbox Found
C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMME
25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME time(s)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop>
Code Writtend by me:-
Issue is :- Though the process is running,It is sending the emails.please suggest I beleive some thing wrong in if condition.
tasklist /FI "IMAGENAME eq notepad.exe" /NH
if "%ERRORLEVEL%"=="0" (
mailsend -d xxxx.local -smtp 192.16x.xx.xx -t fareedm@xxxx.xx -c fareedm@xxxx.xx -f oracle@123.ae -sub "Al" <results.txt
) else (
echo Found! logged files into results.txt
)
did you give the fullpath for the blat ? ( i already mentioned in my old post )
WshShell.Run "/full/path/blat -to fareedm@xxx.xx -log blat.log -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True
I did the same but starange error, Please look into this.
C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMM
25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME25 time(
)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop\check.vbs(15, 2) (null): The system c
nnot find the file specified.
C:\Documents and Settings\Fareedm\Desktop>blat
Blat v1.8.2b: WinNT/95 console utility to mail a file via SMTP
by P.Mendes, M.Neal, G.Vollant, T. Charron
http://www.interlog.com/~tcharron/blat.html
syntax:
Blat <filename> -t <recipient> [optional switches (see below)]
Blat -install <server addr> <sender's addr> [<try>[<port>[<profile>]]] [-q]
Blat -profile [-delete | "<default>"] [profile1] [profileN] [-q]
Blat -h [-q]
-install <server addr> <sender's addr> [<try n times> [<port> [<profile>]]]
: set's SMTP server, sender, number of tries and port for profile
(<try n times> and <port> may be replaced by '-').
<filename> : file with the message body ('-' for console input, end with ^Z
-t <recipient> : recipient list (comma separated)
-s <subj> : subject line
-f <sender> : overrides the default sender address (must be known to server)
-i <addr> : a 'From:' address, not necessarily known to the SMTP server.
-c <recipient> : carbon copy recipient list (comma separated)
-b <recipient> : blind carbon copy recipient list (comma separated)
-o <organization>: Organization field
-h : displays this help.
-q : supresses *all* output.
-noh : prevent X-Mailer header from showing homepage of blat
-noh2 : prevent X-Mailer header entirely
-p <profile> : send with SMTP server, user and port defined in <profile>.
-server <addr> : Specify SMTP server to be used. (optionally, addr:port)
-port <port> : port to be used on the server, defaults to SMTP (25)
-hostname <hst>: select the hostname used to send the message
-mime : MIME Quoted-Printable Content-Transfer-Encoding.
-uuencode : Send (binary) file UUEncoded
-base64 : Send (binary) file using base64 (binary Mime)
-try <n times> : how many time blat should try to send. from '1' to 'INFINITE'
-attach <file> : attach binary file to message (may be repeated)
-attacht <file>: attach text file to message (may be repeated)
Note that if the '-i' option is used, <sender> is included in 'Reply-to:'
and 'Sender:' fields in the header of the message.
C:\Documents and Settings\Fareedm\Desktop>