#82699 - 01/12/2105:55 PMEndProc() - Terminate a process using WMI
KdyerKdyer Moderator
Registered: 01/01/03
Posts: 6226
Loc: Tigard, OR
Code:
;NAME: ENDPROC
;AUTHOR: Kent Dyer (leptonator@hotmail.com)
;CONTRIBUTORS: Conrad Wheeler "Radimus", kholm
;ACTION: Terminates a local or remote process using WMI
;SYNTAX: ENDPROC($PROC,optional $COMPUTER)
;VERSION: 1.2
;PARAMETERS: $PROC
; Required string for the name of process you want to kill
; $COMPUTER
; Optional string containing the name of the system you are interested in,
; you could use @WKSTA
;RETURNS: Returncode (0) and PID
;REMARKS: Reference - Terminate all copies of the& nbsp;Notepad process on host TEST01
; Simplified (hopefully) version of kholm's script
; No warning about program being killed.
;DEPENDENCIES: Kixtart 4.0, WMI
;EXAMPLE(s): $COMPUTER = @WKSTA
; $PROC = "NOTEPAD.EXE"
;
; ENDPROC($PROC,$COMPUTER)
;
; Returns:
; 0
; notepad.exe is 1508
FUNCTION ENDPROC($PROC, optional $COMPUTER)
DIM $Process
IF $COMPUTER=''
$COMPUTER='.'
ENDIF
For each $Process in GetObject('winmgmts:{impersonationLevel=impersonate}!\\'+$COMPUTER+'\root\cimv2')
.ExecQuery('Select * from Win32_Process where Name=' +'"'+$Proc+'"')
$Process.Terminate
?$Process.Name+' is '+$Process.ProcessId
Next
ENDFUNCTION
Another way to do this and suppress the results:
Code:
FUNCTION ENDPROC($PROC, optional $COMPUTER)
Dim $Process,$RC
IF $COMPUTER=''
$COMPUTER='.'
ENDIF
For each $Process in GetObject('winmgmts:{impersonationLevel=impersonate}!\\'+$COMPUTER+'\root\cimv2')
.ExecQuery('select * from Win32_Process where Name='+'"'+$PROC+'"')
$RC=$Process.Terminate
Next
ENDFUNCTION
#82701 - 02/06/1901:52 AMRe: EndProc() - Terminate a process using WMI
RadimusRadimus Moderator
Registered: 00/01/06
Posts: 5120
Loc: Tampa, FL
here is a modifid version
code:
;************************************************************************** FUNCTION FindPROC($PROC,optional $COMPUTER, optional $terminate) dim $GetObject, $Select if not $computer $computer=@wksta endif $GetObject="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER" $select="select * from Win32_Process where Name='$PROC'" For each $Process in GetObject("$GetObject").ExecQuery("$select") if $terminate $Process.Terminate endif $FindPROC=$Process.ProcessId Next ENDFUNCTION
[ 19 June 2002, 01:54: Message edited by: Radimus ]
ja. think like the name says, this is "soft" kill. you can as example kill services with this like with the real kill. (something I do when get mad, kill -f "svchost.exe")
not sure if there is force as there is no force in taskmanager either.
#82712 - 04/10/3010:04 AMRe: EndProc() - Terminate a process using WMI
NTDOCNTDOC Administrator
Registered: 00/07/28
Posts: 11013
Loc: CA
Kent,
Can you please update your post to either Jooel's code or this code, or some other code that does support NoVarInStrings.
You post is the only version that shows on the UDF mirrors which currently does not support this option.
NOTE: Jooel's code currently has an error in it in the fact that the IF $COMPUTER does not work as it can not be blank since it is not optional at the moment.
Code:
Function EndProc($proc, optional $strComputer) DIM $Process If $strComputer='' $strComputer='.' EndIf For Each $Process In GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2").ExecQuery("Select * from Win32_Process where Name= " +'"'+$Proc+'"') $Process=$Process.Terminate Next EndFunction