Showing posts with label Tasks. Show all posts
Showing posts with label Tasks. Show all posts

Wednesday, January 30, 2008

Program to Handle windows Processes and kill when required using VBScript.

FriendZ this is to maintain the windows processes with out own logic without bothering with self -scheduling windows tasks.

sComputer ="."
Set oWMI = GetObject("winmgmts:\\" & sComputer & "\root\CIMV2")
Object_OnTimer7510
Sub Object_OnTimer7510
sTotalHandle = 0
sTotalThread = 0
Set oWin32_OS = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each oItem In oWin32_OS
'sTotalHandle= oItem.TotalHandle
sFreePhysicalMemory = oItem.FreePhysicalMemory
sFreeVirtualMemory = oItem.FreeVirtualMemory
sTotalProcesses = oItem.NumberOfProcesses
sTotalVirtualMemorySize = oItem.TotalVirtualMemorySize
sTotalVisibleMemorySize = oItem.TotalVisibleMemorySize
Next
sSystemCache = sTotalVisibleMemorySize - sFreePhysicalMemory
sCommitLimit = sTotalVirtualMemorySize - sTotalVisibleMemorySize
text1= VbCrLf & "sTotalHandle :" & Space(16-Len(sTotalHandle))& sTotalHandle & VbCrLf & "sTotalThread :" & Space(16-Len(sTotalThread)) & sTotalThread & VbCrLf & "sTotalProcesses :" & Space(16-Len(sTotalProcesses)) & sTotalProcesses & VbCrLf & "sTotalVisibleMemorySize:" & Space(16-Len(sTotalVisibleMemorySize)) & sTotalVisibleMemorySize & VbCrLf & "sFreePhysicalMemory:" & Space(16-Len(sFreePhysicalMemory)) & sFreePhysicalMemory & VbCrLf & "sSystemCache :" & Space(16-Len(sSystemCache)) & sSystemCache & Space(16) & VbCrLf & "sCommitLimit :" & Space(16-Len(sCommitLimit)) & sCommitLimit & Space(16)
MsgBox text1
set servicelist = oWMI.ExecQuery("Select * from Win32_Process")
For Each service in servicelist
sname = sname & service.ProcessId & ":" & lcase(service.name) & Space(1)
'MsgBox service.name
Next
MsgBox sname
xml_file = InputBox("Enter which file you have to termimate :")
flag=True
For Each service in servicelist
If service.name = xml_file Then
service.Terminate()
flag= false
End if
Next
If flag then
MsgBox "File Name dose not exist"
Else
MsgBox xml_file & " process terminated"
End If
Set oWMI = Nothing
Set oWin32_OS = Nothing
Set servicelist = Nothing
End Sub