#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