The next script opens a cmd window to call an external command, and after using it the cmd window stays open. how do i close it??
Because wshShell.Quit doesn't work, it returns an error. Is there any of way of closing it?
this is the script
Option Explicit
Dim objWMIService, objProcess, objFSO, objTextFile
dim colProcess,colServices, colItems
dim objItem, objService
Dim strComputer, strProcessKill, strProcessMem
Dim memLimit, processMem
Dim mustKill
Dim WshShell
Const ForAppending = 8
Set WshShell = WScript.CreateObject("WScript.Shell")
strComputer = "."
strProcessKill = "'DLLHOST.EXE'"
strProcessMem = "'DLLHOST'"
memLimit = 10000
mustKill = 0
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
dim intRC
For Each objProcess in colProcess
processMem = objProcess.WorkingSetSize/1024
If processMem >= memLimit Then
mustKill = 1
End If
if mustKill = 1 then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\informe_dllhost.txt", ForAppending, True)
objTextFile.WriteLine(now & vbnewline & " Process has been killed with " & processMem & " Kb" & vbnewline & vbNewLine)
objTextFile.Close
wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True
WScript.Quit
end if
Next
WScript.Quit
Select all Open in new window
Open in new window
and then run the .bat file instead of pskill directly. the exit command should now close the command window.