Re: Close almost all files/programs?



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




.



Relevant Pages

  • Re: SP3 "access denied" message at updating registry part of download
    ... It doesn't tell you to save a notebook - it tells you to open notepad, ... that script you created. ... Download and then install the Subinacl.exe file. ...
    (microsoft.public.windowsupdate)
  • Re: Javascripts will NOT run in IE6
    ... Open Notepad and copy this there: ... >>B) First start by going to Internet Options of IE ... >>the Advanced tab and then the Restore Defaults ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: XP Home Ed. SP3 access denied error
    ... Download and then install the Subinacl.exe file. ... might word-wrap) into Notepad. ... Double-click the Reset.cmd file to run the script. ...
    (microsoft.public.windowsxp.general)
  • Re: Batch file question
    ... The 'echo' does not understand paths with spaces, notepad does. ... Exercising it at the command line "callstation A B C D" fails. ... The script ...
    (microsoft.public.windowsxp.customize)
  • Re: Programmatically Changing Screen Resolution
    ... HAVEN'T TRIED .NET YET SO NOT SURE IF THIS WOULD WORK BUT IN NOTEPAD YOU COULD CREATE A SCRIPT AND NAME IT XXXX.SCR AND AWAY YOU GO ... SUB MAIN ... DIM HEIGHT_YOU_WANT AS INTEGER ...
    (microsoft.public.windowsxp.customize)

Loading