Closing cmd window after script execution

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)
	wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True	
    end if

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the easiest way is creating a 2 line bat file
C:\pskill.exe -accepteula dllhost.exe

Open in new window

and then run the .bat file instead of pskill directly. the exit command should now close the command window.
Lee W, MVPTechnology and Business Process AdvisorCommented:
Why open a command prompt - why not just use:
wshShell.Run "C:\pskill.exe -accepteula dllhost.exe", 1, True

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee is correct, there's no need to run cmd.exe just to start another exe.
But in case you're interested, the issue is in line 31:
wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True

Open in new window

With the "/k", you're telling cmd.exe to run the command following, and then Keep the window open.
Replace the "/k" with a "/c", and the window will Close after execution of the command.
wshShell.Run "cmd /c C:\pskill.exe -accepteula dllhost.exe", 1, True

Open in new window

Both solutions provided by Lee W. and oBda should work.
If it bothers you that you see all kind of popping command windows then also replace the "1" with 7. The Run method will then start the command window minimized and without activating it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.