Re: Close almost all files/programs?
- From: "Ed" <ed_millis@xxxxxxxxxxxxxxxxx>
- Date: Thu, 4 Jan 2007 11:16:32 -0700
Thanks, jw. I copied the script into Notepad, saved it as a .vbs file and
then launched it (double-click). NotePad opened, I got a long list of
processes, and that was it. I still had a blank NotePad window open. The
length of the process list was too long for me to see if NOTEPAD.EXE was on
it, although notepad.exe (all small letters) was running in the Task
Manager, so I added the small letters version to the If ... Then and it
found and killed it.
So I need to figure out what the process name is of either what I want to
terminate or what I want to keep, and construct the proper loop to act on
what gets terminated or bypass what doesn't, and I'm set. Am I missing
anything?
Ed
The script is running,
"mr_unreliable" <kindlyReplyToNewsgroup@xxxxxxxxxxx> wrote in message
news:uTG%236eCMHHA.4848@xxxxxxxxxxxxxxxxxxxxxxx
Ed, if you happen to have wmi (windows management instrumentation)
installed, then you coud use the win32_Process class.
You can use win32_process class to "enumerate" (make a listing of)
the processes (applications) running on your system.
You then go through the list, and terminate (close) the ones you
don't want.
There is a demo script attached.
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
p.s. if you _don't_ have wmi installed, you can download it
for free from microsoft (msdn).
Ed wrote:
I'm very new to scripting, and I'm hoping for some help. I'd like to
create
a script that would close all files and programs on my computer, except
for
certain ones. I'm thinking I would use FileSystemObject to set objects
to
files, check the name, and if the extension didn't match close the file
and
quit the program.
So:
-- Is this even possible to do?
-- Do I have the right idea to start?
-- How do I make sure I don't close system processes?
Ed
--------------------------------------------------------------------------------
' walk the process list demo, using wmi v1.5, jw 09Jul00
' (note: this demo adapted from msdn mag, Apr 2000, wmi article by ???)
' 12Jul00: modified to demo Process.Terminate
Option Explicit
Dim sProcList ' as string
Dim oWMI, Process ' as objects
Dim oShell ' as object
Dim sNotepad ' as string
' launch notepad (to use as something to terminate)
sNotepad = "NOTEPAD.EXE"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "c:\windows\" & sNotepad
WScript.Sleep 400 ' give notepad some time to load...
Set oWMI = GetObject("winmgmts:")
sProcList = "(Process.Handle - Process.Name)" & vbCrLf & vbCrLf '
initialize
for each Process in oWMI.InstancesOf("Win32_Process")
sProcList = sProcList & CStr(Process.Handle) & " - " & Process.Name &
vbCrLf
if (Process.Name = sNotepad) then
MsgBox("Killing: " & sNotepad & " app now!")
Process.Terminate
End If
next
' report on the processes you just found, inc. the one you killed.
MsgBox sProcList,, " << Current Process List (from wmi) >> " ' show the
results
Set oWMI = nothing ' clean up
Set oShell = nothing
Wscript.Quit
.
- Follow-Ups:
- Re: Close almost all files/programs?
- From: mr_unreliable
- Re: Close almost all files/programs?
- References:
- Close almost all files/programs?
- From: Ed
- Re: Close almost all files/programs?
- From: mr_unreliable
- Close almost all files/programs?
- Prev by Date: Re: "pool" a tightly controlled set of Excel instances
- Next by Date: Re: RGB/HEX question
- Previous by thread: Re: Close almost all files/programs?
- Next by thread: Re: Close almost all files/programs?
- Index(es):
Relevant Pages
|
Loading