Jump to content

Help...Please Change Batch File To Wscript


sayyut

Recommended Posts

@echo off

Title Check WMI Prosesse and Start

TASKLIST | find /i "cleanmgr.exe"

if errorlevel==1 goto :cleanmgr

goto :Rep

:cleanmgr

@echo Start Program cleanmgr

start cleanmgr.exe

goto :END

:END

exit

:Rep

@echo Process on running

pause

exit

BATCH FILE I Know.....

BUT WSCRIPT I Don'Know..... Help me....

-------------------------------------------------------------

I wold like Wscript Script Check Processes cleanmgr.exe Running... Loop Every 20 Min

But Process cleanmgr.exe stop I wold like Script Start cleanmgr.exe

Link to comment
Share on other sites

  • 3 weeks later...

This will do the checking and start if necessary. It is better that you set the as a scheduled task instead of looping every 20 minutes. But, I have included a timer loop.

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList, Running

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

Do
For Each objProcess in colProcess
Running = ""
If objProcess.Name = "cleanmgr.exe" Then Exit For
Running = "False"
Next
If Running = "False" Then Run "C:\program files\cleanmgr\cleanmgr.exe"
wscript.sleep 120000000
Loop

Sub Run(ByVal sFile)
Dim shell

Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub

Hope this helps.

PS - Don't forget to edit the path to the program to run.

~Jonnyboy

Edited by Jonnyboy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...