Posts

Showing posts from February, 2010

Some tricks and codes in VBScript

'Sample VBScript to kill a program Option Explicit Dim objWMIService, objProcess, colProcess Dim strComputer, strProcessKill strComputer = "." strProcessKill = "'application.exe'" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcess = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = " & strProcessKill ) For Each objProcess in colProcess objProcess.Terminate() Next WScript.Quit ' End of WMI Example of a Kill Process 'Sample VBScript to create a file Dim oAPI, oBag Set oAPI = CreateObject(“MOM.ScriptAPI”) Set oBag = oAPI.CreatePropertyBag() Set objFSO = CreateObject(“Scripting.FileSystemObject”) strFile = “C:\myfile.log” If objFSO.FileExists(strFile) Then Call oBag.AddValue(“Status”,”Ok”) Call oAPI.Return(oBag) Else Call oBag.AddValue(“Status”,”Error”) Call oAPI.Return(oBag) E

how to execute query from VBScript in script two state monitor SCOM

here is code : 'define and create objects for passing values in 2 state to SCOM Dim oAPI, oBag Set oAPI = CreateObject("MOM.ScriptAPI") Set oBag = oAPI.CreatePropertyBag() StrConnect = "PROVIDER=SQLOLEDB.1;Integrated Security=SSPI;INITIAL CATALOG=DBName;DATA SOURCE=ServerName" Set cnt = CreateObject("ADODB.Connection") cnt.Open StrConnect set recordSet = CreateObject("ADODB.Recordset") SQLStr = " select * from .... " recordSet.Open SQLStr, cnt,1,1 TotalRecords = recordSet.RecordCount recordSet.Close : set recordSet = nothing cnt.Close : set cnt = nothing 'We have to handle Status value from SCOM and create rule for each state If TotalRecords >= 0 Then Call oBag.AddValue("Status","ERROR") Else Call oBag.AddValue("Status","OK") End If Call oAPI.Return(oBag)