ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

FBSL - Process killer

(1/2) > >>

Gerome:
' ------------------------------------------------
' // PROCESS KILLER
' // April, 7th 2006
' // By Gerome GUILLEMIN
' // Requires : WSH COM interface installed
' ------------------------------------------------

Process_killer.fbs
--- ---#Option Explicit

If standalone = false Then
    Fbsl2exe( Command(1) )
    Exitprogram(1)
End If

#DllDeclare kernel32( "GetEnvironmentVariable" )

Sub Main()
    Dim $strProcess = Inputbox("Process name to kill :", "Name :", "Excel.exe" ), %iResult = 0
    iResult = KillProcess( strProcess )
    $AppType CONSOLE
    Print "--------------------------------------------------------"
    If iResult = 0 Then
        Print "No '" & strProcess & "' process to kill was found :/"
    Else
        Print "Found "& iResult & " '" & strProcess & "' processe(s) to kill :)"
    End If
    Print "--------------------------------------------------------"
    Sleep(2000)
End Sub

' ------------------------------------------------
' // PROCESS KILLER
' ------------------------------------------------
Function %KillProcess( Byval $szProcess, Byval $szPassword = "" )
    Dim $strComputer = GetEnvironmentVar("COMPUTERNAME")
    Dim $strDomain   = GetEnvironmentVar("USERDOMAIN")
    Dim $strUser     = GetEnvironmentVar("USERNAME")

    Dim %objSWbemLocator = CreateObject( "WbemScripting.SWbemLocator" )

    Dim %objWMIService   = GetValue( "%o", objSWbemLocator, ".ConnectServer(%s, %s, %s, %s, %s, %s )", _
                           strComputer, "root\CIMV2", strUser, szPassword, "MS_409", "ntlmdomain:" & strDomain )

    Dim %colProcessList  = EnumBegin( objWMIService, ".ExecQuery(%s)", _
                           "SELECT * FROM Win32_Process WHERE Name = '" & szProcess & "'" )

    Dim %objProcess, %iCounter = 0
    While EnumGetNext( colProcessList, objProcess ) = 0
        Print GetValue( "%s", objProcess, ".Name" ) & " killed!"
        Callmethod( objProcess, ".Terminate" )
        Incr(iCounter)
    Wend

    Releaseobject( objSWbemLocator ): Releaseobject( objWMIService )
    Releaseobject( colProcessList ):  Releaseobject( objProcess )
    Return iCounter
End Function

' ------------------------------------------------
' // GETENVIRONMENTVAR
' ------------------------------------------------
Function GetEnvironmentVar( Byval $sName ) As String
    Dim $GetEnvironmentVar: Alloc( GetEnvironmentVar, 255 )
    GetEnvironmentVariable( sName, GetEnvironmentVar, 255 )
    Return GetEnvironmentVar
End Function

brotherS:
It might be nice for you to add a few comments, for what purposes you made it, how to use it, etc. etc. :)

Gerome:
Hello,

It might be nice for you to add a few comments, for what purposes you made it, how to use it, etc. etc. :)
-brotherS (April 07, 2006, 01:01 PM)
--- End quote ---

Purpose is simple :
Either beeing able to kill from your computer a named running process immediately and irremediably, either beeing able to kill from your computer a distant process that is running from a server where for sure you are granted to access and then killing a distant process.
This sample can be handy for administrative tasks.

Carol Haynes:
Does this work in any version of Windows - otherwise aren't there built in command line admin tools in Windows XP/2003 ? (eg. SC.exe)

Gerome:
Hi,
Does this work in any version of Windows - otherwise aren't there built in command line admin tools in Windows XP/2003 ? (eg. SC.exe)
-Carol Haynes (April 07, 2006, 07:43 PM)
--- End quote ---

This script uses WSH, it's an optional COM component that natively comes with XP, and with 2k it comes with services pack, and finally you can install WSH onto versions inferior to 2k like NT4 and Win 9.x.
SC.EXE is part of XP and >, and is unavailable for other versions...

The purpose of my script was to encapsulate a wsh code into Fbsl to show perfect interaction between FBSL and WSH COM interface.

For instance and witrh a bit of patience, it just would say you can develop your own IDE for 3rd party COM interfaces with FBSL, and making a step by step WSH or JS or VBS debugger, yes really you can.

Navigation

[0] Message Index

[#] Next page

Go to full version