Question

Locked

WMI scripts - killing/opening processes

By simonstuart05 ·
Hey All,

I'm new to WMI scripting (about 2 hours or so!) so bare with me a wee bit. Basically, I've got 2 machines i look after remotetly (both Win 2k).

Now, I need to kill a couple of processes on both machines and start one process.

Checked a few posts out here and while I understood what the program was doing..I was struggling alittle bit on following the code.

Any tips for a newb is appreciated.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Try

by jimmy-jam In reply to WMI scripts - killing/ope ...

I tested this script on my own PC. When you copy and paste watch for extra white space which can goof things up sometimes. To terminate 2 processes there is a portion of the script you will just have to duplicate. Good luck.

Dim strComputer, objWMIService, colProcesses, objProcess, strExe, objcalc, objProgram, objProc

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

'copy from here to next for an additional process to terminate

Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'powershell.exe'")
For Each objProcess In colProcesses
objProcess.Terminate
next

'copied following from www.computerperformance.co.uk/vbscript/wmi_process_start.htm

strExe = "Calc.exe"
' Obtain the Win32_Process class of object.
Set objProc = objWMIService.Get("Win32_Process")
Set objProgram = objProc.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod("Win32_Process", "Create", objProgram)

Collapse -

What about

by simonstuart05 In reply to Try

Thanks Jimmy I believe I will find that extremely useful. Just one other quick question...

If I wish to execute the script locally, but have it run remotely. I'm guessing it's a whole new script in that case?

Collapse -

Nope

by jimmy-jam In reply to What about

Assuming the credentials you are logged into your PC with are valid on the remote PC, you can replace

strComputer = "."

with

strComputer = "remote machine name or IP"

If you have several PC's you can create a script for each PC and store and execute them locally.

Back to Tips and Tricks Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums