Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 09, 2016, 07:41:56 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FBSL - Process killer  (Read 3197 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
FBSL - Process killer
« on: April 07, 2006, 12:00:02 PM »
' ------------------------------------------------
' // 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

Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: April 07, 2006, 12:03:38 PM by Gerome »

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,136
    • View Profile
    • Donate to Member
Re: FBSL - Process killer
« Reply #1 on: April 07, 2006, 01:01:06 PM »
It might be nice for you to add a few comments, for what purposes you made it, how to use it, etc. etc. :)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - Process killer
« Reply #2 on: April 07, 2006, 02:59:53 PM »
Hello,

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

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.
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - Process killer
« Reply #3 on: April 07, 2006, 07:43:46 PM »
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

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - Process killer
« Reply #4 on: April 07, 2006, 07:52:31 PM »
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)

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.
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - Process killer
« Reply #5 on: April 07, 2006, 08:06:49 PM »
'k got it now ...